DATA Step, Macro, Functions and more

macro to output put statements into a text file

Accepted Solution Solved
Reply
Super Contributor
Posts: 312
Accepted Solution

macro to output put statements into a text file

I used %put to call the values of macro variables, and wanted to output some text too.

I got the outout to the log file, but not the results window, nor to a ODS rtf or pdf file.

Is there a way to do it?

 

proc sql;
    select count(DUPI) into :all_never
        from demoplay.never_played_all;
    select count(DUPI) into :nj_never
        from demoplay.NJ_never_played;
    select count(DUPI) into :outside_nj
        from demoplay.Outside_NJ_never_played;
quit;
%put %str(Total never played: ) %all_never; %put %str(Total never played in NJ: ) &nj_never; %put %str(Total never played outside NJ: ) %outside_nj;

 

 

 


Accepted Solutions
Solution
‎05-04-2016 10:48 AM
Super User
Posts: 10,497

Re: macro to output put statements into a text file

You might provide a little more detail of what you are attempting with "output text in proc sql".

A simple select unless you use the NO print option will direct the Proc SQL output to the active ODS Destination:

 

Proc sql;

   select *

   from SASHELP.CLASS;

quit;

 

Will create a table of output with the contents of the SASHELP.CLASS dataset.

If I create a phrase variable that would be the result:

proc sql;
   select catx(' ',name,"weighs",weight,"pounds at age",age) as Phrase
   from SASHELP.Class;
quit;

Will generate something like:

 

Phrase
Alfred weighs 112.5 pounds at age 14
Alice weighs 84 pounds at age 13
Barbara weighs 98 pounds at age 13
Carol weighs 102.5 pounds at age 14
Henry weighs 102.5 pounds at age 14
James weighs 83 pounds at age 12
Jane weighs 84.5 pounds at age 12
Janet weighs 112.5 pounds at age 15
Jeffrey weighs 84 pounds at age 13
John weighs 99.5 pounds at age 12
Joyce weighs 50.5 pounds at age 11
Judy weighs 90 pounds at age 14
Louise weighs 77 pounds at age 12
Mary weighs 112 pounds at age 15
Philip weighs 150 pounds at age 16
Robert weighs 128 pounds at age 12
Ronald weighs 133 pounds at age 15
Thomas weighs 85 pounds at age 11
William weighs 112 pounds at age 15

View solution in original post


All Replies
Super User
Posts: 6,936

Re: macro to output put statements into a text file

Why so complicated? Do a simple select in SQL and let ODS route the output.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super Contributor
Posts: 312

Re: macro to output put statements into a text file

Thank you, @KurtBremser.

I want to output some text too, not only the numbers.
Super User
Posts: 10,497

Re: macro to output put statements into a text file

Depending on exactly what you want then perhaps use of ODS TEXT is more appropriate.

 

 

Other wise you will need to use something like:

 

data _null_;

   file "<desired full path and output file name goes here";

   put "Total never played: &all_never";
   put "Total never played in NJ:  &nj_never";
   put "Total never played outside NJ:  &outside_nj";

run;

 

NOTE: %PUT only writes to the log and you were referencing your macro variable incorrectly.

Super Contributor
Posts: 312

Re: macro to output put statements into a text file

Thank you, @ballardw.

This works.

 

Do you know how to output text in proc sql?

Solution
‎05-04-2016 10:48 AM
Super User
Posts: 10,497

Re: macro to output put statements into a text file

You might provide a little more detail of what you are attempting with "output text in proc sql".

A simple select unless you use the NO print option will direct the Proc SQL output to the active ODS Destination:

 

Proc sql;

   select *

   from SASHELP.CLASS;

quit;

 

Will create a table of output with the contents of the SASHELP.CLASS dataset.

If I create a phrase variable that would be the result:

proc sql;
   select catx(' ',name,"weighs",weight,"pounds at age",age) as Phrase
   from SASHELP.Class;
quit;

Will generate something like:

 

Phrase
Alfred weighs 112.5 pounds at age 14
Alice weighs 84 pounds at age 13
Barbara weighs 98 pounds at age 13
Carol weighs 102.5 pounds at age 14
Henry weighs 102.5 pounds at age 14
James weighs 83 pounds at age 12
Jane weighs 84.5 pounds at age 12
Janet weighs 112.5 pounds at age 15
Jeffrey weighs 84 pounds at age 13
John weighs 99.5 pounds at age 12
Joyce weighs 50.5 pounds at age 11
Judy weighs 90 pounds at age 14
Louise weighs 77 pounds at age 12
Mary weighs 112 pounds at age 15
Philip weighs 150 pounds at age 16
Robert weighs 128 pounds at age 12
Ronald weighs 133 pounds at age 15
Thomas weighs 85 pounds at age 11
William weighs 112 pounds at age 15
☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 237 views
  • 0 likes
  • 3 in conversation