BookmarkSubscribeRSS Feed
atul_desh
Quartz | Level 8

Hello,

 

I'm having two single quote (') seprated by delimeter.

its is reading them as 1 and var3 is equal to "8" which should be var4 in second observation. 


data ds1;
infile datalines dsd dlm='|';
input var1-var4;
datalines;
1|2|3|4|
9|'|'|8|
run;

proc print data=ds1;
run;

 

Also I don't want to "~" before variable because in actual case I don't which two consuctive variable will contain single quotation.

 

Actual text which I'm trying to import from unix contains 200 variable and that is tab delimited.. I've given above example of pipe delimited just to more readable. 

 

Please help me out !!

 

Thanks

Atul Deshmukh 

4 REPLIES 4
RickAster
Obsidian | Level 7

The behavior you are observing is the purpose of the DSD option as documented. When I removed the DSD option the data read as intended.

Tom
Super User Tom
Super User

So if your input file never has null values then you can just drop the DSD option.

But if your input file has both null values (ie examples where two delimiters are right next to each other and it means there is value that empty) then you will need to process the data line before reading it.

So you could change the |'| into |"'"| so that SAS will see that the single quote is in fact a quoted string and so the DSD option will work.

input @;
do while (index(_infile_,"|'|"));
  _infile_=tranwrd(_infile_,"|'|","|""'""|");
end;
input var1-var5;

Or if you never have actual quoted string values that would also require the DSD option then perhaps you can drop the DSD option from the INFILE and instead convert the || into |.| to indicate a missing value.

input @;
do while (index(_infile_,"||"));
  _infile_=tranwrd(_infile_,"||","|.|");
end;
input var1-var5;
atul_desh
Quartz | Level 8
But my actual file is not pipe delimited it is tab delimeted... Here I've given example of pipe delimited just to get more understand.

Tom
Super User Tom
Super User

@atul_desh wrote:
But my actual file is not pipe delimited it is tab delimeted... Here I've given example of pipe delimited just to get more understand.


So in the fix use tabs instead of pipe character.  The hex code for a tab is '09'x.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1484 views
  • 0 likes
  • 3 in conversation