BookmarkSubscribeRSS Feed
JUMMY
Obsidian | Level 7

I have five permanent sas data sets I want to merge together by the ID. The data sets are Y(5 variables), YY(12 variables), YYY(47 variables), YYYY(36 variables) and YYYYY(24 variables). Some of the variables start with the letter "i" and needs to be formatted using the indicators (1='yes' and '0'=no) and gender variable - female (1='yes', 0='no'). Here is my sas:

 

Libname in "E:\locationofdata";

 

data raw;

set in.Y in.YY in.YYY in.YYYY in.YYYYY;

run;

 

proc sort data=raw;

by ID;

run;

 

proc print data=raw;

run;

 

data merge;

merge Y YY YYY YYYY YYYYY;

by ID;

run;

 

proc print data =merge;

run;

 

Is the sas data step right? How do I format to include the indicators as stated above?

 

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

Your two data steps are radically different, and we have no idea what result you want.

Please post a small example of BEFORE and AFTER data.

How to convert datasets to data steps
How to post code

Astounding
PROC Star

Agreeing with @ChrisNZ, you really have not described the problem.  You say you want to merge permanent data sets, but use a SET statement to accomplish that.  When you finally get around to using a MERGE statement, you refer to data sets that don't exist.  You absolutely will have to clarify what your objective is.

Reeza
Super User

A bit simplistic, but in general,

SET appends data sets - so when you're trying to add rows to a data set.

MERGE combines data sets side by side - so you add columns. 

 

You're doing both which does not seem correct. Without more details though not sure we can help you here. 

 


@JUMMY wrote:

I have five permanent sas data sets I want to merge together by the ID. The data sets are Y(5 variables), YY(12 variables), YYY(47 variables), YYYY(36 variables) and YYYYY(24 variables). Some of the variables start with the letter "i" and needs to be formatted using the indicators (1='yes' and '0'=no) and gender variable - female (1='yes', 0='no'). Here is my sas:

 

Libname in "E:\locationofdata";

 

data raw;

set in.Y in.YY in.YYY in.YYYY in.YYYYY;

run;

 

proc sort data=raw;

by ID;

run;

 

proc print data=raw;

run;

 

data merge;

merge Y YY YYY YYYY YYYYY;

by ID;

run;

 

proc print data =merge;

run;

 

Is the sas data step right? How do I format to include the indicators as stated above?

 


 

 

ballardw
Super User

@JUMMY wrote:

I have five permanent sas data sets I want to merge together by the ID. The data sets are Y(5 variables), YY(12 variables), YYY(47 variables), YYYY(36 variables) and YYYYY(24 variables). Some of the variables start with the letter "i" and needs to be formatted using the indicators (1='yes' and '0'=no) and gender variable - female (1='yes', 0='no'). Here is my sas:

 

Libname in "E:\locationofdata";

 

data raw;

set in.Y in.YY in.YYY in.YYYY in.YYYYY;

run;

 

proc sort data=raw;

by ID;

run;

 

proc print data=raw;

run;

 

data merge;

merge Y YY YYY YYYY YYYYY;

by ID;

run;

 

proc print data =merge;

run;

 

Is the sas data step right? How do I format to include the indicators as stated above?

 


What indicators? You did not use any.

Are the names of the data sets involved n two different libraries?: in.Y  would be a dataset belonging to the IN library and Y to WORK library. So merge Y YY YYY YYYY YYYYY; refers to different data sets

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 709 views
  • 0 likes
  • 5 in conversation