For example after the sort
the below data step , i see the attached instead of the 1111s in front of the id, it shows just characters and letters. but i need the ones, why would the ones disapper in the datastep?
proc sort data=prov2 ;
by key;
format id $20.;
run;
Sorting just changes the order. Since you are sorting by KEY and not by ID the location of the values of ID that start with 111 will be potentially be different than before. Did you search the whole file for them?
But the NODUPKEY option will remove OBSERVATIONS. So it is possible the observations with values of ID that start with 111 were deleted because there was already some other observation with that same value of KEY that was kept.
If you merge two tables that have same named variables that are not part of the merge key then the value from the table listed last in the merge statement will "win".
I've renamed in below merge the id variables so they individual names per source table. Investigate the result and see if this explains to you where these "leading 1" went. It's certainly not a truncation issue and it certainly has nothing to do with a Proc Sort that never changes values.
proc sort data=test.prov2;
by key;
run;
proc sort data=test1.prov;
by key;
run;
data hce.provider_merge5;
length id $20;
merge test.prov2(rename=(id=id2)) test1.prov(rename=(id=id1));
by key;
if id1 ne id2 then output;
run;
Hello @Rsadiq
Please provide a sample of your data as sas7bdat file?
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 25. Read more here about why you should contribute and what is in it for you!
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.