BookmarkSubscribeRSS Feed
LSchafer
Calcite | Level 5

Hi,

I am trying to create an ODS destination file for the excel tagset using macro variables. The files contain data by site and patient, so would be:

Data_12_001.xls

Data_12_002.xls

Etc.

The siteid and subjid are in the file sitepatientlist.

I have the following code, which is not working:

data _null_;

do obsnum=1 to last by 1;

            set outlib.sitepatientlist point=obsnum nobs=last;

%let parmSite = &siteid;

%let parmSubj = &subjid;

%let fpath = "U:\outputs\data_&parmSite.._&parmSubj..xls";

ODS TAGSETS.EXCELXP file=&fpath;

…etc

I get an unresolved reference for parmSite and parmSubj. I can see that they populate correctly in the %let statements, but the fpath does not resolve.

I have tried many variations - anybody have any ideas?

Thanks

2 REPLIES 2
art297
Opal | Level 21

While you didn't show all of your code, it appears that you are trying to both assign and use a macro variable within the same datastep.  That won't work as the macro variable can only be accessed after that datastep.

Some alternatives are suggested in the following paper: http://www2.sas.com/proceedings/sugi31/115-31.pdf

ballardw
Super User

I am guessing that you are trying to create the macro variables parmSite and parmSubj from the values of siteid and subjid. You are getting the errors because siteid and subjid are NOT macro variables.

In the data step you are looking for:

call symput(parmsite,siteid);

call symput(parmsubj,subjid);

run;

then your fpath assignment may work. Depending on length assignments and values you may want to use strip to remove unwanted blanks such as

call symput(parmsite,strip(siteid));

if you get unwanted spaces in the resolved value for fpath.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1617 views
  • 0 likes
  • 3 in conversation