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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.