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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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