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

Hi i am stuck with basic prob.

 

I have two datasets Data1 having variables a, b, c, d like 

a b c d

2 3 5 6

1 0 1 4

0 1 4 5

2 4 3 1

 

and Data2 having variables ch and lm

ch lm

p   3

q   5

l    7

m  4

 

I Need my output having variables ch (Data2), (a,b,c,d) from Data1 and a new variable "label" having "1" if any of the value in the row of data1 is >= 5.

 

my output data will have variables "ch", "a"," b", "c", "d", "label".

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

I don't have a sound understanding of your req nor your data. Is this what you want?

 

data want;

merge data2(drop=lm) data1;

if max(a,b,c,d)>=5 then label=1;

run;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

I don't have a sound understanding of your req nor your data. Is this what you want?

 

data want;

merge data2(drop=lm) data1;

if max(a,b,c,d)>=5 then label=1;

run;

ervinodsingh
Obsidian | Level 7

Sir Thanks for your quick response,

Actually, It was a toy example.

Can you generalize if i have too many variables in Data1. So,  i can't put them manually.

 

Thanks

novinosrin
Tourmaline | Level 20

You could use a variable list using -- (Double dash)

 

so for example: max(of a--d);

Astounding
PROC Star

Given that:

 

  • You need to examine every numeric variable in Data1, and
  • The new variable is based on variables in Data1 only,

You would be better off creating the new variable first, and combining the data sets later.  For example:

 

data data1_new;

set data1;

label = (max(of _numeric_) >= 5);

run;

 

Then do combine them, you can use either SET or MERGE.  It depends on what you want the result to be if there are different numbers of observations in DATA1 and DATA2.  Here is one possibility to consider:

 

data want;

set data1_new;

set data2 (drop=lm);

run;

ervinodsingh
Obsidian | Level 7

Thanks Austonding.. yours code is also working 

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
  • 5 replies
  • 1879 views
  • 3 likes
  • 3 in conversation