BookmarkSubscribeRSS Feed
Rsadiq
Calcite | Level 5
For example the document shows that it is 111111n for example but after sorting the result shows n for id. It truncates the 1's for some reason. I just wanted to see how to fix that since I need the full ID
Rsadiq
Calcite | Level 5

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;

Tom
Super User Tom
Super User

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.

Patrick
Opal | Level 21

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;
Sajid01
Meteorite | Level 14

Hello @Rsadiq 
Please provide a sample of your data as sas7bdat file?

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
  • 19 replies
  • 922 views
  • 1 like
  • 5 in conversation