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

data have;
infile datalines dlm='{''^''}' missover;
input id name $ salary;
datalines;
{^}{^}55000
{^}rohit{^}
3{^}giridhar{^}
;
run;
it has work when all columns has data but above scenario it won't work

help me out thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use DLMSTR not DLM and add the DSD option.

In DLM each character is treated as an individual delimiter, i.e. you have 4 delimiters, " , {, }, ^

 

DLMSTR used the group of characters as a single delimiter. 

 

I don't think you need the quotes in there unless your delimiter includes quotes, which it doesn't in your example data. 

Make sure your example data reflects your actual data as much as possible, because we can't see it. 

 

 

 

View solution in original post

5 REPLIES 5
Reeza
Super User

Use DLMSTR not DLM and add the DSD option.

In DLM each character is treated as an individual delimiter, i.e. you have 4 delimiters, " , {, }, ^

 

DLMSTR used the group of characters as a single delimiter. 

 

I don't think you need the quotes in there unless your delimiter includes quotes, which it doesn't in your example data. 

Make sure your example data reflects your actual data as much as possible, because we can't see it. 

 

 

 

ganeshmule
Fluorite | Level 6
Thank you for your reply
But it has only three delimiter as under
Dlm='{^}' only so in this case it will not work
Could you please write infile statement as per you
Norman21
Lapis Lazuli | Level 10

As Reeza has stated, instead of DLM, you need DLMSTR and DSD, in your example as follows:

 

infile datalines dlmstr='{^}' dsd missover ;

Norman.
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

Tom
Super User Tom
Super User

I think that your question is really how to use a multiple character string as the delimiter when reading text from a file.

If you want a specific sequence of characters to be the delimiter then you need to use the DLMSTR= option on the INFILE statement.

If you specify multiple characters in the DLM= option each individual character is treated as a delimiter.  So '{^}' is not one delimiter but three of them next to each other.

 

The reason it properly read the lines did not have any empty values is because you did not include the DSD option.  Without the DSD option adjacent delimiters do not indicate a missing value.  So having three delimiters between each value did not mean there were two missing values.  But you need the DSD option to distinguish which values are missing when not all values are present, like in your example.

data have;
  infile datalines dsd dlmstr='{^}' truncover;
  input id name $ salary;
datalines;
{^}{^}55000
{^}rohit{^}
3{^}giridhar{^}
;

PS. Don't include quotes in the DLMSTR value unless they are actually part of the string.

PS. Get in the habit of using the TRUNCOVER instead of MISSOVER option.  They generally work the same, but most of the time you will want the input to read the characters it can find instead of giving you a missing value. 

ganeshmule
Fluorite | Level 6
thank you

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
  • 5 replies
  • 1669 views
  • 2 likes
  • 4 in conversation