BookmarkSubscribeRSS Feed
Bal23
Lapis Lazuli | Level 10
I need to modify a program; originally, it is a very simple data step.

Data want;
Set old;
Where rownum=3;
Run;

Now I need to add some new rules because of different ways of calculating the score, instead of just pick up the score on the third row before. I cannot pick the third row (one size does not fit all!).
The rules are listed as follows

1.	If id in (‘4’,’5’,’110’,’119,’1000’) then score=sum1/sum2;
2.	If id in (‘34’,’12’,’245’,’beaa’,’geee2’) then score= sum(aver)/sumrownum:
3.	If id in (‘rt’, ‘t32’,’g45’,’2’,’578’) then score = score where appears on the first row, that is rownum=1
4.	If id in (‘a2’,’c34’) then score=score where appears on the second row, that is rownum=2;
….
So I am thinking of doing this in a datastep, it would be easy for the first two steps, but for the last two, it seems that I need use “where…” and I do not know how to do. Or do I have to set up a subdataset? That will be time consuming

Can anybody show me how to do? Thanks.


2 REPLIES 2
Reeza
Super User

1. Post sample data

2. Post sample expected output

 

Astounding
PROC Star

It takes a little work, but you can get the values in this way:

 

data want;

set old;

retain score1 score2;

****************** more statements to calculate SCORE

if rownum=1 then score1 = score;

else if rownum=2 then score2 = score;

drop score1 score2;

run;

 

Now SCORE1 is the calculated SCORE value for ROWNUM=1, and presumably gets calculated before it is needed to generate SCORE values for later values of ROWNUM.  Just use SCORE1 and SCORE2 as part of  your SCORE calculations.

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