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

Hi,

 

I am trying to include a numeric variable in an ODS text statement. Is there a way to do that?

 

The code is something like this:

 

ods text= "^S={just=l} Note: [xxx] subjects are missing data at this time."

I want to substitute the variable count in place of the Xs.

It is part of a macro code and hence do not want to hard code it.

 

Thanks,

Neha.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Create a macro variable that holds the value and then use it in the text.

 

proc sql noprint;
select count(*) into :n_count from have where missing(var);
quit;

ods text  = "^S={just=l} Note: [&n_count.] subjects are missing data at this time."

View solution in original post

8 REPLIES 8
Reeza
Super User

Create a macro variable that holds the value and then use it in the text.

 

proc sql noprint;
select count(*) into :n_count from have where missing(var);
quit;

ods text  = "^S={just=l} Note: [&n_count.] subjects are missing data at this time."
analyst_work
Obsidian | Level 7
Could you please explain this code?

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Reeza
Super User

Proc sql creates the macro variable that contains the count. You can use a different method to create the macro variable.

 

The ODS text statement uses the macro variable.

analyst_work
Obsidian | Level 7

 I tried the code and its working, but I am getting parenthesis around the numbers which I don't want. Also, is it possible to get the numbers in words?

Reeza
Super User

The brackets were in your ODS text statement. Remove them.

 

To get them as words use the WORDS. format.

 

proc sql noprint;
select put(count(*), words.) into :n_count from have where missing(var);
quit;

 

 

analyst_work
Obsidian | Level 7

Perfect! Getting them in words now without the parenthesis, but the formatting isnt very accurate:

 

ten          subjects not included

 

How do I get rid of the space and can I capitalize the first letter?

 

analyst_work
Obsidian | Level 7

Also, the code does not output zero. Is there a way to fix this?

ballardw
Super User

Quick and dirty:

 

%let n_count=0;

just before the SQL that does the count.

 

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