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

I have a dataset in the following form, with the input variables Var 1 to Var 3 and required output variable:

Var1     Var2     Var3      OutputVar

a          1          p              1

a          1          q              2

a          2          r               1

b          1         m              1

b          2         n               1

b          2         o               2

For each Var1, the OutputVar needs to be the cumulative frequency of Var 3 grouped by Var2. I need all the variables in the final output data.

Any suggestions please?

Thanks.

VD

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Please try the below code

data have;

input Var1$     Var2     Var3$;

datalines;

a          1          p    

a          1          q    

a          2          r   

b          1         m     

b          2         n     

b          2         o     

;

run;

proc sort data=have;

by var1 var2;

run;

data want;

  set have;

  by var1 var2;

  retain outputvar;

  if first.var2 then outputvar=1;

  else outputvar+1;

run;

Thanks,

Jag

Thanks,
Jag

View solution in original post

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

Please try the below code

data have;

input Var1$     Var2     Var3$;

datalines;

a          1          p    

a          1          q    

a          2          r   

b          1         m     

b          2         n     

b          2         o     

;

run;

proc sort data=have;

by var1 var2;

run;

data want;

  set have;

  by var1 var2;

  retain outputvar;

  if first.var2 then outputvar=1;

  else outputvar+1;

run;

Thanks,

Jag

Thanks,
Jag
VD
Calcite | Level 5 VD
Calcite | Level 5

Thank you, Jag!

It works well.

VD

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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