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

While Import excel file using Proc Import for few subject# ID I am getting some specific character value. Example below.

 

"
3-158-021"   Expecting Subject id should be: 3-158-021 (9 characters)

The below SAS code I have used however, it is not working. any help would be appreciated.

data Keosys_vdr2;
	length SubjectNumber $150;
	set Keosys_vdr1 (firstobs=2);
	subjectnumber=strip(compress(Subject,'"'));
	*subjectnumber1=prxchange('s/\"//',-1,subjectnumber);
	keep SiteNumber subjectnumber subjectnumber1 Current_Status;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

It's not really clear to me what the data actually is here:

 

"
3-158-021" 

 

Is there a carriage return/end of line character in your data?

 

This works for me

 

data want;
    subject='"
3-158-021" ';
    want = compress(subject,'"');
run;


From now on, please help us help you. Please don't say "it is not working" and provide no other information. Please, from now on, do provide the incorrect results that you are getting or the log with errors in it.

--
Paige Miller

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

It's not really clear to me what the data actually is here:

 

"
3-158-021" 

 

Is there a carriage return/end of line character in your data?

 

This works for me

 

data want;
    subject='"
3-158-021" ';
    want = compress(subject,'"');
run;


From now on, please help us help you. Please don't say "it is not working" and provide no other information. Please, from now on, do provide the incorrect results that you are getting or the log with errors in it.

--
Paige Miller
PC7
Fluorite | Level 6 PC7
Fluorite | Level 6

It's because carriage return, I was not getting expected outcome. I tried with below code. Getting expected results. thank you.

	subjectnumber=compress(Subject,'0D0A'x);
FreelanceReinh
Jade | Level 19

Hello @PC7,

 

Maybe it's easier to specify the characters to be kept in the subject ID, e.g., digits and hyphens (cf. the COMPRESS function documentation):

subjectnumber=compress(Subject,'-','kd');

Or display one of the strings in $HEX. format to find out exactly what characters need to be removed. Here's an example where those double quotes are in fact curly quotes:

data _null_;
Subject='3-158-021';
put Subject $hex.;
run;

Result in the log:

93332D3135382D30323194

So this would remove them:

subjectnumber=compress(Subject,'9394'x);

 

 

PaigeMiller
Diamond | Level 26

Excellent idea, @FreelanceReinh 

--
Paige Miller
Tom
Super User Tom
Super User

If your compress function call

subjectnumber=strip(compress(Subject,'"'));

does not remove the character, then you specified the wrong character in the call.

 

So look at what character is actually in your data.  Display it using the $HEX format.  Once you find out what character it is then use a hex literal in the code.  If you are running with ENCODING=UTF-8 and the character is one that uses multiple bytes (basically one that is not between a space and an tilde ) then use KCOMPRESS() instead.

Ksharp
Super User
You could use DEQUOTE() to get rid of quote around this string:

Subject=dequote(Subject);
PC7
Fluorite | Level 6 PC7
Fluorite | Level 6

Hi Ksharp,

I tried with DQUOTE function, still I was getting same results. I think it's because of carriage return. When I tried the below code, Geeting expected outcome.

	subjectnumber=compress(Subject,'0D0A'x);

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2092 views
  • 5 likes
  • 5 in conversation