DATA Step, Macro, Functions and more

Variable in ODS text

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

Variable in ODS text

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.

 


Accepted Solutions
Solution
‎06-07-2016 03:24 PM
Super User
Posts: 19,867

Re: Variable in ODS text

Posted in reply to nehuvarma

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


All Replies
Solution
‎06-07-2016 03:24 PM
Super User
Posts: 19,867

Re: Variable in ODS text

Posted in reply to nehuvarma

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."
Contributor
Posts: 22

Re: Variable in ODS text

Could you please explain this code?

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Super User
Posts: 19,867

Re: Variable in ODS text

Posted in reply to nehuvarma

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.

Contributor
Posts: 22

Re: Variable in ODS text

 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?

Super User
Posts: 19,867

Re: Variable in ODS text

Posted in reply to nehuvarma

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;

 

 

Contributor
Posts: 22

Re: Variable in ODS text

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?

 

Contributor
Posts: 22

Re: Variable in ODS text

Posted in reply to nehuvarma

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

Super User
Posts: 11,343

Re: Variable in ODS text

Posted in reply to nehuvarma

Quick and dirty:

 

%let n_count=0;

just before the SQL that does the count.

 

☑ This topic is solved.

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

Discussion stats
  • 8 replies
  • 428 views
  • 0 likes
  • 3 in conversation