BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

data have;
length Status $25.;
input Status cnt;
return;
datalines;
Tot_pop 10
Curr 5
_30_day 1
Paid 4
;run;

 

Status cnt
Tot_pop 10
Curr 5
_30_day 1
Paid 4

 

Is there a way to calculate the percentage change using Tot_Pop as the base line.  Idea is to divide Curr/Tot_pop and show results on Curr row, then _30_day/tot_pop and show on _30_day row?

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Its really hard to generalize from your example

 

If tot_pop is the sum of the other CNT values, then you don't need it. (Is it always going to be the sum of the other CNT values?)

 

But assuming it is the sum of the other CNT values, get rid of the tot_pop line, delete it from your data set, and then run PROC FREQ to get your percentages.

--
Paige Miller
ballardw
Super User

@Q1983 wrote:

data have;
length Status $25.;
input Status cnt;
return;
datalines;
Tot_pop 10
Curr 5
_30_day 1
Paid 4
;run;

 

Status cnt
Tot_pop 10
Curr 5
_30_day 1
Paid 4

 

Is there a way to calculate the percentage change using Tot_Pop as the base line.  Idea is to divide Curr/Tot_pop and show results on Curr row, then _30_day/tot_pop and show on _30_day row?


I would call this a good example of why not to include summary data in data if Tot_pop is supposed to be the sume of Curr, _30_day and Paid. Especially if you calculated it previously.

 

One take on what I think is similar to what you want:

data have;
length Status $25.;
input Status cnt;
return;
datalines;
Tot_pop 10
Curr 5
_30_day 1
Paid 4
;
run;

proc tabulate data=have;
   where status ne 'Tot_pop';
   var cnt;
   class status;
   table status all='Tot_pop',
         cnt *(sum pctsum)
   ;
run;

 

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
  • 289 views
  • 3 likes
  • 3 in conversation