BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SM1
Obsidian | Level 7 SM1
Obsidian | Level 7

I am working with a string variable (DELIV) that should have a maximum of 11 characters or digits. To prepare this variable, I used the COMPRESS function to remove all spaces.

 

To check and then clean this variable, I ran the following syntax:

 

data checklength;

set check;

    length_deliv = length(deliv);
    lengthn_deliv = lengthn(deliv);
    lengthc_deliv = lengthc(deliv);
run;

 

Here are the results from the SAS Output

length_deliv Frequency Percent Cumulative
Frequency Cumulative
Percent 2 10 11 13 33
10.2110.21
20.4230.63
46397.2746697.90
91.8947599.79
10.21476100.00

lengthn_deliv Frequency Percent Cumulative
Frequency Cumulative
Percent 2 10 11 13 33
10.2110.21
20.4230.63
46397.2746697.90
91.8947599.79
10.21476100.00

lengthc_deliv Frequency Percent Cumulative
Frequency Cumulative
Percent 255
476100.00476100.00

 

When I ran a proc print of the 9 observations where length_deliv and lengthn_deliv = 13,  this is what the values looked like:

 

091705JUN07

262350JUL07

122245OCT07

261635OCT07

152145NOV07

181845NOV07

281820FEB08

021727APR08

090015APR08

 

Why does length_deliv and lengthn_deliv = 13 and not 11?

 

Any help will be most appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use the 's' modifier with the COMPRESS() function to remove them as well and have no trailing invisible spaces.

 

http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#n0fcshr0ir3...

 

Example 3 covers this in the doc.

View solution in original post

10 REPLIES 10
Reeza
Super User

What are the formats and types associated with the variable?

SM1
Obsidian | Level 7 SM1
Obsidian | Level 7

I ran a PROC CONTENTS statement to get this info.

 

Type = Char

Len = 255

Format = $255

Informat = $255

Reeza
Super User

Check the values iwth a HEX format, you may have tabs or something else in there. 

 

Or apply the compress function first to remove any non printable characters - you need to use a modifier and recheck the data.

SM1
Obsidian | Level 7 SM1
Obsidian | Level 7

I compressed the variable to remove spaces before checking the lengths.

 

I have several similar variables and none of the others have any values that are gt 11.

 

I'll figure out how to check the values with a HEX format.

 

Thanks!

PGStats
Opal | Level 21

Try printing the Lengthn = 13 values with format $hex26. format to see the non printing characters.

PG
SM1
Obsidian | Level 7 SM1
Obsidian | Level 7

@PG

 

I ran this syntax:

 

proc print data = checklength;
    where lengthn_deliv eq 13;
    format deliv $hex26.;
run;

 

I don't know how to read the SAS output for the 9 values of DELIV where lengthn = 13:

 

30393030313541505230380D0A
30323137323741505230380D0A
32383138323046454230380D0A
3138313834354E4F5630370D0A
3135323134354E4F5630370D0A
3236313633354F435430370D0A
3132323234354F435430370D0A
3236323335304A554C30370D0A

3039313730354A554E30370D0A

PGStats
Opal | Level 21

0D0A is CR-LF, carriage return - linefeed. So those are the invisible characters that are part of your mysterious values.

PG
Reeza
Super User

Use the 's' modifier with the COMPRESS() function to remove them as well and have no trailing invisible spaces.

 

http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#n0fcshr0ir3...

 

Example 3 covers this in the doc.

SM1
Obsidian | Level 7 SM1
Obsidian | Level 7

@Reeza

 

Thank you!

 

I used this syntax to compress a number of similar variables:

 

data want; *compress values to get rid of all spaces;
    set have;
        array change(9)  Inc Alert Launch OnSce Locate Recov Deliv RTB SubmitDate;
                do i = 1 to 9;
                change(i)=compress(change(i), , 's');
    end;
run;

 

It worked perfectly.

 

Thank you!

SM1
Obsidian | Level 7 SM1
Obsidian | Level 7

@PGStats

 

Indeed, there were invisible characters.

 

Thanks for explaining 0D0A .

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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