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.
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.
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.
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.
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.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.