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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 455 views
  • 0 likes
  • 2 in conversation