BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
friedtukeywings
Fluorite | Level 6

I've spent hours on this, but it will not work when I try to run it as a dataset. What I am trying to do is read in multiple datasets with the same ending, but different prefixes. Such as:

d170726_1 d170726_2 d170822 d170925

They are datasets within the same fiscal quarter, so I want to combine them into one quarter overall, but first I must run some logic. It is much more simpler to do this with a macro since this will be a continuing issue for the entire year since the data comes in waves. I want to make the process generalizable, but there needs to be some sorting, etc. before the merging. So... I placed these names in a .txt file using:

data null; length dsn $9. ; infile "&proj.&sp.CY2017&sp.datasets.txt" truncover; input @1 dsn $9. ;

i+1;
ii = left(put(i,2.));
call symput('n',ii);
call symput('dsn'||ii,left(dsn));

run;

when run %put all , the codes show: dsn1 = 1232_test, dsn2 = 42521_1_test, etc.

Cool great. I use this in the code data&year..&&dsn&i._mst_tbl... And these are my results 😧

d170726_1 WARNING: Apparent symbolic reference DSN1_MST_TBL not resolved. WARNING: Apparent symbolic reference DSN1_CPT_CODE not resolved. WARNING: data2017.&dsn1_cpt_code does not exist

Please help 😞 What am I doing wrong? I'm going insane.

1 ACCEPTED SOLUTION

Accepted Solutions
friedtukeywings
Fluorite | Level 6

My apologies. Yes, the dataset should resolve to the dsn1, dsn2, and so forth variables which should contain the actual dataset name so that dsn1 the 1st dataset listed in the .txt file.

View solution in original post

5 REPLIES 5
Cynthia_sas
SAS Super FREQ
Hi:
You do not show enough code. For example, you do not show how &proj, &sp, &I or &year is created. You only show CALL SYMPUT for &dsn.

The warning in the LOG is trying to tell you that something about your indirect reference is specified incorrectly. An indirect reference is when you use multiple ampersands to delay the resolution for part of a macro variable reference while you another part of the macro variable gets resolved. Then due to the way that macro variables are scanned and resolved, multiple ampersands cause the Macro processor to "hold" and "rescan" a reference with multiple && until all the resolution and substitution are finished.

For a simple example, please refer to this paper: https://support.sas.com/resources/papers/proceedings13/120-2013.pdf on page 10-11 at the discussion of indirect reference in regard to the macro variable reference &&muppet&num.

cynthia
friedtukeywings
Fluorite | Level 6

I am sorry,

 

This code is set within a large macro such as:

 

%macro sashelp (year =, ms_tbl =);

 

Which then corresponds to:

%sashelp (2015, garden) and so forth.

 

[Edit] Forgot to answer this, the &proj and &_sp_ macro variables are just the path of the file.

Astounding
PROC Star

I'm not sure you showed us what you want this to resolve into:

 

&&dsn&i._mst_tbl

 

So I'll assume it should take the value &DSN1 (then &DSN2, then &DSN3, etc.), and append _mst_tbl at the end.  If that's the intent, a small change should take care of things

&&dsn&i.._mst_tbl

 

With two dots in the middle, the first one delimits &i, then the second one delimits &DSN1.

friedtukeywings
Fluorite | Level 6

My apologies. Yes, the dataset should resolve to the dsn1, dsn2, and so forth variables which should contain the actual dataset name so that dsn1 the 1st dataset listed in the .txt file.

Tom
Super User Tom
Super User

What am I doing wrong?

Perhaps it is that you are making your program too complicated?

 

Someone already has given you the answer that you need to add another period to mark the end of the &DSNx macro reference since you need to resolve two different macro variables in front of the fixed text. 

&&dsn&i.._MST_TBL 

That should have been pretty clear from the warning messages

WARNING: Apparent symbolic reference DSN1_MST_TBL not resolved.
WARNING: Apparent symbolic reference DSN1_CPT_CODE not resolved.

that you got.

 

But if you just expand your code to make the steps a little clearer it will be easier for both you and SAS to figure out what you are doing.

%do i=1 to &nobs ;
....
%let basename=&&dsn&i ;
%let master=&basename._MST_TBL ;
%let cptfile=&basename._CPT_CODE;
data &master ;
  set &cptfile ;
  ....

%end;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 991 views
  • 0 likes
  • 4 in conversation