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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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