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.;
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.