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
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
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
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
thank you Hai and ksharp for the help. it worked great!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.