BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
axescot78
Quartz | Level 8

I have 2 data sets that I am trying to link by an alphanumeric variable (job code). I already found that one data set contains "non-breaking spaces" (which I didn't know exist). I am finding some of the codes still are not matching. For example, I have a code "AB000". When I do a proc freq before linking these data sets, I find two "AB000" listed. The search function in SAS results window finds both entries using "AB000". I also tried matching with "%AB000%" and using compress to account for any characters that I may not be seeing, and still getting the same result. I tried exporting the proc freq to excel and original data set to csv, and still I am not seeing a difference. Has anyone had experience with this?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The proc freq output is likely showing two, or more values, because of leading spaces. The table generator for output left justifies the text even if there are leading spaces.

Try using the LEFT or STRIP function on the variable(s) in a data step and then see if the result changes.

A brief example to demonstrate:

data example;  
   length string $ 8;
   string='abc';output;
   string=' abc';output;
   string='   abc';output;
run;

proc freq data=example;
   tables string;
run;

data newex;
   set example;
   string=strip(string);
run;
proc freq data=newex;
   tables string;
run;

 

 

View solution in original post

3 REPLIES 3
ballardw
Super User

The proc freq output is likely showing two, or more values, because of leading spaces. The table generator for output left justifies the text even if there are leading spaces.

Try using the LEFT or STRIP function on the variable(s) in a data step and then see if the result changes.

A brief example to demonstrate:

data example;  
   length string $ 8;
   string='abc';output;
   string=' abc';output;
   string='   abc';output;
run;

proc freq data=example;
   tables string;
run;

data newex;
   set example;
   string=strip(string);
run;
proc freq data=newex;
   tables string;
run;

 

 

Tom
Super User Tom
Super User

Are you looking at the output produced by ODS (such as HTML, PDF or RTF)?  If then ODS has a nasty habit of not displaying leading spaces.

 

Try just removing the leading spaces.

data fix;
  set have;
  job_code = left(job_code);
run;

Otherwise try looking at the values using the $HEX format to see the actual characters in the field.

proc freq data=fix ;
  where job_code like '%ABOOO%';
  tables job_code / noprint out=counts;
run;
proc print data=counts;
  format job_code $hex14. ;
run;
Tom
Super User Tom
Super User

Also make sure that those oval shaped characters are all the same.

 

Old typewriters did not have keys for one or zero as you could just use the lowercase L and uppercase o to put the same ink on the page.

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
  • 3 replies
  • 911 views
  • 0 likes
  • 3 in conversation