DATA Step, Macro, Functions and more

ODS Excelxp filename using macro variables

Reply
Occasional Contributor
Posts: 17

ODS Excelxp filename using macro variables

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

PROC Star
Posts: 7,363

Re: ODS Excelxp filename using macro variables

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

Super User
Posts: 10,500

Re: ODS Excelxp filename using macro variables

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.

Ask a Question
Discussion stats
  • 2 replies
  • 581 views
  • 0 likes
  • 3 in conversation