DATA Step, Macro, Functions and more

how to store_user_

Accepted Solution Solved
Reply
Regular Contributor
Posts: 205
Accepted Solution

how to store_user_

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!


Accepted Solutions
Solution
‎06-28-2017 12:00 PM
Super User
Posts: 10,500

Re: how to store_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


All Replies
Super User
Posts: 5,083

Re: how to store_user_

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.

Solution
‎06-28-2017 12:00 PM
Super User
Posts: 10,500

Re: how to store_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;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 115 views
  • 2 likes
  • 3 in conversation