BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
BayzidurRahman
Obsidian | Level 7

Hi,

I have 4 variables as var1…var4. I want to identify the observations where same value occurs in more than 1 variable and then keep the value at it’s first occurrence.

For example,

The dataset I have:

Var1 var2 var3 var4

1          2          3          4

0          0          4          9

1          1          1          20

0          1          2          2

1          0          2          1

5          9          9          9

3          3          3          3         

 

The dataset I want:

Var1 var2 var3 var4

1          2          3          4

0          .           4          9

1          1          .           20

0          1          2          .

1          0          2          .

5          9          .           .

3          .           .           .

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input Var1 var2 var3 var4;
cards;
1          2          3          4
0          0          4          9
1          1          1          20
0          1          2          2
1          0          2          1
5          9          9          9
3          3          3          3      
;

data want;
 set have;
 array v{*} var1-var4;
 array x{*} x1-x4;
 do i=1 to dim(v);
  if v{i} not in x then x{i}=v{i};
   else v{i}=.;
 end;
 keep var1-var4;
run;

View solution in original post

4 REPLIES 4
JosvanderVelden
SAS Super FREQ
The logic you want to implement is not clear since the second observation doesn't follow the guidelines you describe. In that observation you have two '1's! If I understand your guidelines the second observation should be 1 . . 20. Can you explain why that is not the case?
BayzidurRahman
Obsidian | Level 7

Yes- you are right. it is about the 3rd observation

The dataset I want:

Var1 var2 var3 var4

1          2          3          4

0          .           4          9

1          .          .           20

0          1          2          .

1          0          2          .

5          9          .           .

3          .           .           .

Ksharp
Super User
data have;
input Var1 var2 var3 var4;
cards;
1          2          3          4
0          0          4          9
1          1          1          20
0          1          2          2
1          0          2          1
5          9          9          9
3          3          3          3      
;

data want;
 set have;
 array v{*} var1-var4;
 array x{*} x1-x4;
 do i=1 to dim(v);
  if v{i} not in x then x{i}=v{i};
   else v{i}=.;
 end;
 keep var1-var4;
run;
BayzidurRahman
Obsidian | Level 7

Thanks very much.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 339 views
  • 1 like
  • 3 in conversation