DATA Step, Macro, Functions and more

how to read three delimiter in file using base sas

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

how to read three delimiter in file using base sas

[ Edited ]

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


Accepted Solutions
Solution
‎10-28-2017 03:46 PM
Super User
Posts: 22,874

Re: how to read three delimiter in file using base sas

Posted in reply to ganeshmule

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


All Replies
Solution
‎10-28-2017 03:46 PM
Super User
Posts: 22,874

Re: how to read three delimiter in file using base sas

Posted in reply to ganeshmule

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. 

 

 

 

Contributor
Posts: 22

Re: how to read three delimiter in file using base sas

Posted in reply to ganeshmule
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
Frequent Contributor
Posts: 102

Re: how to read three delimiter in file using base sas

[ Edited ]
Posted in reply to ganeshmule

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 (TS1M4) X64_7PRO WIN 6.1.7601 Service Pack 1 Workstation

Super User
Super User
Posts: 7,860

Re: how to read three delimiter in file using base sas

[ Edited ]
Posted in reply to ganeshmule

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. 

Contributor
Posts: 22

Re: how to read three delimiter in file using base sas

thank you
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 197 views
  • 2 likes
  • 4 in conversation