BookmarkSubscribeRSS Feed
wllm_fox
Calcite | Level 5

Hey guys,

 

This is my first post, just let me know if you need me to elaborate. 

 

I've created a proc freq table that I've outputted to a work file, and it looks like the below:

 

StatusCOUNTPERCENT
Successful2000.769231
Unsuccessful500.192308
Unknown100.038462

 

I want to get the PERCENT value where the status was "Successful" and assign it to a macro variable that I can use at a later part of the programme. 

 

Does anyone know how I can do this? Thank you in advance for you help.

2 REPLIES 2
Tom
Super User Tom
Super User

You can create a macro variable using CALL SYMPUTX() function.

%let percent=;
data _null_;
  set have;
  if status='Successfull" then call symputx('percent',percent');
run;

If you want to test whether the string in that macro variable is larger than some other floating point value make sure to use %SYSEVALF() as the normal %EVAL() macro function used in %IF will only handle integer arithmetic.

%if %sysevalf(&percent > 0.5 ) %then %do;
....
%end;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 6307 views
  • 0 likes
  • 2 in conversation