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

hi,

i created this output below using couple datasteps with arrays.  I'm struggling to do the following: return the ID number where the value increases month-over-month. In the example given below the output would be ID 16 (since in april12 it had gone up to 114 from 100)

I'm writing this in VBA without any issues, since the code loop through cells and compare the values from the previous record using index functions. I'm struggling transitioning this to SAS. any help is much appreciated. 

ID  Month Score

16 Jan12 112

16 Feb12 110

16 March12 100

16 April12 114

35 Jan12 120

35 Feb12 115

35 March 106

35 April 100

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input ID $ Month $ Score;
cards;
16 Jan12 112
16 Feb12 110
16 March12 100
16 April12 114
35 Jan12 120
35 Feb12 115
35 March 106
35 April 100
;
run;
data want;
 set have;
 if id eq lag(id) and dif(score) gt 0;
run;

Ksharp

View solution in original post

3 REPLIES 3
Haikuo
Onyx | Level 15

If your data comes as is, lag() or dif() will be sufficient:

data have;

input ID $ Month $ Score;

cards;

16 Jan12 112

16 Feb12 110

16 March12 100

16 April12 114

35 Jan12 120

35 Feb12 115

35 March 106

35 April 100

;

data want;

  set have;

  by id notsorted;

d=dif(score);

  if not first.id and d>0;

keep id;

run;

Haikuo

Ksharp
Super User
data have;
input ID $ Month $ Score;
cards;
16 Jan12 112
16 Feb12 110
16 March12 100
16 April12 114
35 Jan12 120
35 Feb12 115
35 March 106
35 April 100
;
run;
data want;
 set have;
 if id eq lag(id) and dif(score) gt 0;
run;

Ksharp

chayo
Calcite | Level 5

thank you Hai and ksharp for the help. it worked great!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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