BookmarkSubscribeRSS Feed
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

Hello,

 

Using SAS 9.4, I am running the following code to try and create a wide data set for a matched analysis. I have 1 linking variable "subclass". I have renamed all variables from the 2nd data set with the suffix "_wide". The goal is to create 1 data with set all variables and their _wide counterpart (i.e. sex and sex_wide) from both observations with the same subclass. When I run the merge statement at the end, all of the data from "_wide" data set is missing. Any help on how I can correct this issue would be greatly appreciate. Thank you 

data wide1;
	set ing.analysis;
	if subclass in: ('1') then output;
run;*NOTE: The data set WORK.WIDE1 has 181 observations and 84 variables.;

data wide2;
	set ing.analysis;
	if subclass in: ('2') then output;
run;*NOTE: The data set WORK.WIDE2 has 362 observations and 84 variables.;

*add suffix to end of matched variables;
proc sql;
 select cats(name,'=',name,'_wide') AS  wide2
          into :list
          separated by ' '
          from dictionary.columns
          where libname = 'WORK' and memname = 'WIDE2';
quit;

data  wide2;
	set wide2 (rename = (&list));
	rename subclass_wide = subclass;
run;*NOTE: The data set WORK.WIDE2 has 362 observations and 84 variables.;

proc sort data= wide1;	
	by subclass;
run;
proc sort data= wide2;	
	by subclass;
run;

data ing.wide_analysis;
	merge wide1 wide2;
	by subclass;
run;*NOTE: There were 181 observations read from the data set WORK.WIDE1.
NOTE: There were 362 observations read from the data set WORK.WIDE2.
NOTE: The data set ING.WIDE_ANALYSIS has 543 observations and 167 variables.;
2 REPLIES 2
Tom
Super User Tom
Super User

181 + 362 = 543

 

So none of the values of SUBCLASS that are in WIDE1 are in WIDE2.

 

If you want the values to merge they have to match.

GS2
Obsidian | Level 7 GS2
Obsidian | Level 7
Thank you. That was an oversight on my part.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 349 views
  • 0 likes
  • 2 in conversation