SAS Programming

DATA Step, Macro, Functions and more
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!!!!

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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