DATA Step, Macro, Functions and more

format of call symput

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 76
Accepted Solution

format of call symput

Hi All,

 

I have a column variable named Pvalue, then I use call symput to output a value. for example:

I have a simple dataset below:

 

variable        Pvalue         Pvalue_1

score            0.00003          <0.001

math             0.02                0.02

 

The format of Pvalue_1 is Pvalue5.3 get from Pvalue.

I am using below code to output a variable's value:

data _null_;
set scatter1;
if variable="score";
call symput("P", Pvalue_1);
run;
%put (&P);

 

But the output P is 0.00003 not <0.001

Any idea to solve this? I want p is <0.001.

 

Thanks,

C


Accepted Solutions
Solution
‎05-11-2017 05:19 PM
Super User
Posts: 10,500

Re: format of call symput

[ Edited ]

If you do not specify a Format for your numeric variable then the result is converted using BEST fromat

Macro variables only handle text so you need to tell SAS exactly which text you want.

 

Try

call symput("P", Put( Pvalue_1, pvalue6.3));

That will have a trailing 0 for 0.020 but should not be a problem for most uses.

 

You may want to consider using Call SYMPUTX to reduce the chances of unwanted leading spaces in some uses.

View solution in original post


All Replies
PROC Star
Posts: 551

Re: format of call symput

A very small correction to your code solves this:

 

data scatter1;
input variable $ Pvalue Pvalue_1 $;
datalines;
score 0.00003 <0.001
math 0.02 0.02
;

data _null_;
   set scatter1;
   if variable="score" then call symput("P", Pvalue_1);
run;
%put (&P);
Solution
‎05-11-2017 05:19 PM
Super User
Posts: 10,500

Re: format of call symput

[ Edited ]

If you do not specify a Format for your numeric variable then the result is converted using BEST fromat

Macro variables only handle text so you need to tell SAS exactly which text you want.

 

Try

call symput("P", Put( Pvalue_1, pvalue6.3));

That will have a trailing 0 for 0.020 but should not be a problem for most uses.

 

You may want to consider using Call SYMPUTX to reduce the chances of unwanted leading spaces in some uses.

Frequent Contributor
Posts: 76

Re: format of call symput

Yes, that works!!

Thanks so much!!!!

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 157 views
  • 1 like
  • 3 in conversation