BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GeorgeSAS
Lapis Lazuli | Level 10

How to save _user_ defined macro into a dataset? read the text file created below?

 

proc printto log="c:\temp\testlog.txt";
run;
%put _user_;
proc printto ;
run;

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

What are you going to do with the results?

 

Note that there exists a data view you can address as SASHELP.Vmacro or with proc sql Dictionary.Macros that contains all of the macro variable definitions at the time you inspect. The following will have all variables. Add Where Scope ne 'AUTOMATIC' to get the macro variables you declared.

 

Data want;

   set sashelp.vamacro;

run;

 

or

Proc Sql;

    create table want as

    select *

    from dictionary.macros

   ;

quit;

View solution in original post

2 REPLIES 2
Astounding
PROC Star

You would be better off using existing tools for this purpose.

 

Use PROC SQL to take a look at dictionary.macros ... you should find all macro variables there, with fields that identify which ones are user-created.  It should be easy enough to save a subset of that, as a SAS data set.

 

The one tricky part:  macro variables that are longer than 200 characters are saved in 200-character chunks, across multiple observations.  Of course with your %PUT _USER_ statement, those would pose a problem as well.

ballardw
Super User

What are you going to do with the results?

 

Note that there exists a data view you can address as SASHELP.Vmacro or with proc sql Dictionary.Macros that contains all of the macro variable definitions at the time you inspect. The following will have all variables. Add Where Scope ne 'AUTOMATIC' to get the macro variables you declared.

 

Data want;

   set sashelp.vamacro;

run;

 

or

Proc Sql;

    create table want as

    select *

    from dictionary.macros

   ;

quit;

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