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 

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