Hi Experts,
I have a dataset which contains 3 visits to ID.
data have;
input Id Count var1;
cards;
12 1 56
12 2 45
12 3 65
25 1 87
25 2 98
25 3 23
;
Now I added,
15 nos - 12
20 nos - 25 in the Id variable. (Only Id not other variables)
I have to continue the count value as followed which already exist.
Please suggest some Ideas to solve this problem.
Thanks in advance!
I don't understand. Post two data steps:
Your changes:
Now I added,
15 nos - 12
20 nos - 25 in the Id variable. (Only Id not other variables)
And your desired results:
I have to continue the count value as followed which already exist.
Huh??? What are you trying to say here?
Dear @ScottBass
I'm Sorry for the trouble, Let me explain in detail...
data Dataset1;
input Id Count var1;
cards;
12 1 56
12 2 45
12 3 65
25 1 87
25 2 98
25 3 23
;
data Dataset2;
input Id;
cards;
12
12
12
12
12
25
25
25
25
;
I merged these 2 datasets as given below. I need to continue the Count value (Mentioned in Bold) which followed by the existing value from 3.
Id | Count | Var1 |
12 | 1 | 56 |
12 | 2 | 45 |
12 | 3 | 65 |
25 | 1 | 87 |
25 | 2 | 98 |
25 | 3 | 23 |
12 | 4 | |
12 | 5 | |
12 | 6 | |
12 | 7 | |
12 | 8 | |
25 | 4 | |
25 | 5 | |
25 | 6 | |
25 | 7 |
data Dataset1;
input Id Count var1;
cards;
12 1 56
12 2 45
12 3 65
25 1 87
25 2 98
25 3 23
;
data Dataset2;
input Id;
cards;
12
12
12
12
12
25
25
25
25
;
data temp;
set dataset1 dataset2(in=inb);
by id;
flag=inb;
drop count;
run;
data want;
set temp;
by id;
if first.id then count=0;
count+1;
run;
proc sort data=want;
by flag id;
run;
Just to be clear, Var1 will have missing values for those observations, correct?
Exactly...
The desired result is in Dataset1 with this approach
data temp;
do until (last.Id);
set Dataset1;
by Id;
end;
call missing(var1);
do until (last.Id);
set Dataset2;
by Id;
Count=Count+1;
output;
end;
run;
proc append base=Dataset1 data=temp;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.