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
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.
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);
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.
Yes, that works!!
Thanks so much!!!!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.