BookmarkSubscribeRSS Feed
Sathish_jammy
Lapis Lazuli | Level 10

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!

 

6 REPLIES 6
ScottBass
Rhodochrosite | Level 12

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?


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
Sathish_jammy
Lapis Lazuli | Level 10

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.

 

IdCountVar1
12156
12245
12365
25187
25298
25323
124 
125 
126 
127 
128 
254 
255 
256 
257 

 

Ksharp
Super User
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;
PeterClemmensen
Tourmaline | Level 20

Just to be clear, Var1 will have missing values for those observations, correct?

PeterClemmensen
Tourmaline | Level 20

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1262 views
  • 1 like
  • 4 in conversation