BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fengyuwuzu
Pyrite | Level 9

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;

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

5 REPLIES 5
fengyuwuzu
Pyrite | Level 9
Thank you, @Kurt_Bremser.

I want to output some text too, not only the numbers.
ballardw
Super User

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.

fengyuwuzu
Pyrite | Level 9

Thank you, @ballardw.

This works.

 

Do you know how to output text in proc sql?

ballardw
Super User

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

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