SASERAIN Interface Engine

Example 53.1 Retrieving Weather Forecast Data for One Location

(View the complete code for this example.)

When you are specifying one location by city, it is important to also specify the country. Because spaces are allowed in city names and country names, a comma (without spaces) is required to separate the city name from the country name. The following statements enable you to access the World Weather Online data for Paris. The output is shown in Output 53.1.1.


options validvarname=any;

title 'World Weather Online Data for Paris';
LIBNAME myLib saserain "%sysget(RAIN_DATA)"
   OUTXML=gstart
   AUTOMAP=replace
   MAPREF=MyMap
   XMLMAP="%sysget(RAIN_DATA)gstart.map"
   APIKEY='XXXXXXXXXXXXXXXXXXXX'
   QUERY='Paris,France'
   FORMAT=xml
   NUM_OF_DAYS=1;

data howCool;
   set myLib.gstart ;
run;
proc contents data=howCool; run;
proc print data=howCool(obs=6); run;

Output 53.1.1: World Weather Online Data for Paris

World Weather Online Data for Paris

Obs date AreaName Country Region oc latitude longitude maxtempC maxtempF mintempC mintempF totalSnow_cm sunHour uvIndex time tempC tempF windspeedMiles windspeedKmph winddirDegree winddir16Point weatherCode weatherDesc precipMM humidity visibility pressure cloudcover HeatIndexC HeatIndexF DewPointC DewPointF WindChillC WindChillF WindGustMiles WindGustKmph FeelsLikeC FeelsLikeF chanceofrain chanceofremdry chanceofwindy chanceofovercast chanceofsunshine chanceoffrost chanceofhightemp chanceoffog chanceofsnow chanceofthunder
1 2018-05-11 Paris France Ile-de-France 1 48.8670 2.33300 24 74 15 59 0 5.8 6 0 12 53 5 8 138 SE 113 Clear 0 65 10 1021 6 13 55 7 44 11 52 6 9 11 52 0 83 0 33 82 0 0 0 0 0
2 2018-05-11 Paris France Ile-de-France 1 48.8670 2.33300 24 74 15 59 0 5.8 6 600 13 56 4 7 80 E 113 Clear 0 75 20 1020 0 13 56 9 48 13 55 5 8 13 55 0 87 0 0 91 0 0 0 0 0
3 2018-05-11 Paris France Ile-de-France 1 48.8670 2.33300 24 74 15 59 0 5.8 6 1200 20 68 7 11 148 SSE 116 Partly cloudy 0 40 20 1017 0 22 71 6 43 20 68 8 13 20 68 0 88 0 16 87 0 0 0 0 0
4 2018-05-11 Paris France Ile-de-France 1 48.8670 2.33300 24 74 15 59 0 5.8 6 1800 22 71 7 11 156 SSE 113 Sunny 0 46 20 1015 6 22 72 9 49 22 71 8 13 22 71 0 81 0 27 76 0 3 0 0 0


The SASERAIN interface engine supports the XML format. The XML data that the World Weather Online website returns are placed in a file named by the OUTXML= option (GSTART). The XML map that is automatically created is assigned the full path name specified by the XMLMAP= option, and the fileref that is used for the map assignment is specified by the MAPREF= option. Because the XMLMAP= option is specified as /sasusr/rain/test/, the SASERAIN engine uses the MAPREF= and XMLMAP= options in the FILENAME statement to assign a file name:

FILENAME MyMap "/sasusr/rain/test/gstart.map";

You can use the MAPREF= and XMLMAP= options to control where the map resides, what you name the map, and how you refer to it with a fileref. You can use the OUTXML= option to name your XML data file; it is described in the section SAS OUTXML File. The XML data file is placed in the current working folder and the SAS data set that is created when the XML data are read into SAS is placed in the location specified by physical-name, which is described in the section The LIBNAME libref SASERAIN Statement. You can refer to your data by using the myLib libref in your SASERAIN LIBNAME statement. The myLib libref is shown inside the DATA step in the SET statement. The SET statement reads observations from the input data set myLib.gstart and stores them in a SAS data set named HowCool, as shown in Output 53.1.1. You can also use the SAS DATA step to perform further processing and to store the resulting time series in a SAS data set; this process is described in the section SAS Output Data Set.

To specify the list of World Weather Online data sets that you want to retrieve, use the QUERY= option. This option accepts a string, enclosed in single quotation marks, that denotes a list of World Weather Online location codes that specify the places where you want the weather forecast data to be selected for the resulting SAS data set. The World Weather Online location codes are separated by semicolons, so valid World Weather Online codes cannot contain embedded semicolons or quotes. The HowCool data set contains the local weather forecast variables The observation range is controlled by the NUM_OF_DAYS= option, which is a required option. The HowCool data set contains observations that start today and end the same day, as specified by the NUM_OF_DAYS option. The frequency of the data is the six-hour default, because the FREQ= option is not specified.

Note: The "%20" is a special character for URL encoding of blanks. If the World Weather Online code that you name in the QUERY= option contains a blank, the SASERAIN engine uses "%20" wherever the blank appears in the World Weather Online code. If the World Weather Online code contains an underscore, then you must use an underscore in the QUERY= option. The underscore and the blank are not equivalent in World Weather Online databases.

Last updated: June 19, 2025