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;
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 |
Why so complicated? Do a simple select in SQL and let ODS route the output.
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.
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 |
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.