BookmarkSubscribeRSS Feed
arunrami
Pyrite | Level 9

Hello Guys,

 

Can anyone tell me is there any way to store the macro variable permanently so that it will exist across all upcoming SAS session too, I read about STORE option and AUTOCALL library but those things for macro code, is that applicable for storing macro variable??

 

Any way to storing and updating macro variable across the session?

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Put the data in a dataset.  Simply put macro is not a system for storing or processing data.  It is a find/replace system for generating text, and only that.

Base SAS which insludes the full programming language, types, datasets and such like, is for storing and processing data.  

Use the right tool for the right job.

 

If it is a parameter, which needs to be available at system startup, then you create that parameter in the autoexec.sas file.  But that is not the system to use for storage of data.

arunrami
Pyrite | Level 9
Since we cant refer the variable from different dataset, I would like to store that in to macro variable and call it when ever needed.

Just an example:-
/*First session*/
Data X;
Set libr.Old;
call symput('prevtime',start_time);/*This should be stored till next session*/
run;

Next session:
Data A;
set New;
if start_time<>&prevtime;
run;



Kurt_Bremser
Super User

The only way to directly get a macro variable into a session is to set it in one of the autoexec resources, and you DO NOT DO THAT dynamically.

Instead, write it to a dataset every time you leave a session:

data sasuser.macrovars;
length
  name $32
  value $64
;
input name;
value = symget(name);
cards;
prevtime
;
run;

And you can now add static(!) code to your autoexec:

data _null_;
set sasuser.macrovars;
call symput(name,value);
run;

Instead of sasuser, use any permanent library you have.

You can add the first code in your EG as code to be submitted after each task and SAS Code, and the second as code being sent when a server connection is established.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

"Since we cant refer the variable from different dataset" - why can't you?  There is merging/joining, formats, lookups etc.  

proc sql;
  create table a as
  select *
  from   new
  where start_time <> (select start_time from libr.old);
quit;

Replaces the two steps you show.

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
  • 5 replies
  • 1643 views
  • 2 likes
  • 3 in conversation