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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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