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

I have two macro variables that correctly resolved from the following PROC SQL functions.

proc sql;

    select count(*) as Total into :totaln from test1;

quit;

proc sql;

    select count(*) as Total into :partn from test2;

quit;

Although they are both macro (character) variables, in essence they are numeric constants from which I am interested in calculating a percentage: pc = (partn/totaln )* 100.

%macro pc;

%let totaln=%left(&totaln);

%let partn=%left(&partn);

t=inputn(&totaln,8.);

p=inputn(&partn,8.);

%let pc=%syseval((p/t)*100);

title "Percent represented: &pc.% ";

%mend pc;

%pc;

The above attempt did not work. The macro does not let me create a constant t or p and gives me an error message: ERROR 180-322: Statement is not valid or it is used out of proper order.

How do I turn  macro character to numeric variable to perform an arithmetic operation?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I think you're looking for something like:

%let pc = %sysevalf ( (&partn / &totaln)*100);

You may want to round the result to desired number of decimals such as

%let pc = %sysfunc(round(&pc, 0.01));

View solution in original post

2 REPLIES 2
ballardw
Super User

I think you're looking for something like:

%let pc = %sysevalf ( (&partn / &totaln)*100);

You may want to round the result to desired number of decimals such as

%let pc = %sysfunc(round(&pc, 0.01));

sonicpoem
Fluorite | Level 6

Thank you.  It worked!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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