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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

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);
ballardw
Super User

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.

echoli
Obsidian | Level 7

Yes, that works!!

Thanks so much!!!!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 9288 views
  • 1 like
  • 3 in conversation