- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have a whole list of state abbreviations that are saved as libnames. I am trying to reference them in a simple macro to generate tables from data in each of these tables. All the files I in these libraries are of the form: state_commonname_date.
The code I had set up for this macro was:
%macro want (state = , date = );
data &state._history;
set &state..&state._commonname_&date.;
run;
%mend want;
For example the table I am setting for Alabama would be al.al_commonname_20180526. Looks like the issue is stemming from the parsing of the periods in the set command.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I suspect that your getting bit by the tokenizer macro interaction bug. Your code will run fine outside of a macro. But inside a macro the dataset name looks like multiple words to SAS instead of just one.
What I like to do is build the name into a macro variable and then use that.
%macro want (state = , date = );
%local indsn outdsn;
%let indsn=&state..&state._commonname_&date.;
%let outdsn= &state._history;
data &outdsn;
set &indsn;
run;
%mend want;
You can also just wrap it in an %unquote() so that it is seen as a single token.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I suspect that your getting bit by the tokenizer macro interaction bug. Your code will run fine outside of a macro. But inside a macro the dataset name looks like multiple words to SAS instead of just one.
What I like to do is build the name into a macro variable and then use that.
%macro want (state = , date = );
%local indsn outdsn;
%let indsn=&state..&state._commonname_&date.;
%let outdsn= &state._history;
data &outdsn;
set &indsn;
run;
%mend want;
You can also just wrap it in an %unquote() so that it is seen as a single token.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
So this is perfect and I'll mark it as the correct solution. I just had a follow up question. If I have a list of around 8 states for a given date, how would I go about adapting this code so that I can put the 8 states into a list and have the macro loop through those 8 states for a fixed date so that 8 separate tables are created?
So I would want:
al.al_commonname_20180526
wv.wv_commonname_20180526
wa.wa_commonname_20180526, etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
do you want _history created in WORK library or state(AL) library? Check for the extra period in data statement.
%macro want (state =al , date =20180526 );
data &state.._history;/* Looks like your missing a period here */
set &state..&state._commonname_&date.;
run;
%mend want;
Suryakiran