BookmarkSubscribeRSS Feed
Jumboshrimps
Obsidian | Level 7

Have several data sets in  folders designated by year - such 2020, 2021, 2022, etc with identical names, except for the last four characters which are MMDD. Each folder has a different libname, no chance of this years' data set  being confused with another year, should they by chance be created exactly one year apart. PROC SQL below finds the most recent (MAX) last four characters in the data set name in that library. If there are two data sets, one is big_data_0205 and the other is big_data_0715, then I want big_data_0715 as that is from July 15 - the most recent by naming convention, and the other is from Feb 5th.  Next year we move on to a different libname.

 

The  sql below does an excellent job, grabbing the max(last_4) data set in the library, and only one data set, from dictionary.tables. 

 

proc sql ;
create table work.tracker_tbl as
select memname, Substr(memname,length(memname)-3,4) as last_4
from dictionary.tables
where libname = 'XXX'                    /* (2022)
and memname like "BIG_DATA%"
having last_4=max(last_4);
quit ;

 

Now I want to use the VALUE of what is contained INSIDE variable memname of the data set "tracker_tbl", NOT the string  "memname" as a variable in PROC SQL.   All efforts have ended up as below where the value stored = "memname".  This is my sixth or seventh iteration.

 

 

DATA NULL;
set work.tracker_tbl;
call symput('tracker', memname);

%put &tracker.;

run;

 


SYMBOLGEN: Macro variable tracker resolves to memname
memname

1 REPLY 1
Tom
Super User Tom
Super User

The code you posted would not set TRACKER to "memname" unless that was the value of the MEMNAME variable.

But the %PUT statement you have would not show you whether or not the value was set because you ran it BEFORE the value was set.  Macro statements like %PUT execute while the code is being analyzed and so before the data step has a chance to run.

Do not use the the old call symput() function. Use the modern CALL SYMPUTX() function and avoid storing the trailing spaces from the MEMNAME variable into the macro variable TRACKER.

Also there's no need to make a dataset named NULL if the goal is just to create a macro variable.  Use the keyword _NULL_ instead so no dataset is made.

%let tracker=BEFORE DATA STEP RUNS;
data _null_;
  set work.tracker_tbl;
  call symputx('tracker', memname);
run;
%put &=tracker;

 

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
  • 1 reply
  • 2087 views
  • 0 likes
  • 2 in conversation