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

I've want to read var2 & var8 with (") in it.

 

I think dsd considering inverted comma as delimeter. 

 

how can I read value ? please help !!

 

data ds2;
infile datalines dsd dlm="|" missover;
input (var1-var8) ($);
datalines;
2|"28 |4|||||29" |
run;

proc print data=ds2;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

My original code had an uncorrected oversight which I'll correct after posting this. The following will work with your tab delimited file:

data ds2;
  infile datalines dlm='09'x missover;
  input @;
  do while (index(_infile_,'0909'x) gt 0);
    _infile_=tranwrd(_infile_,'0909'x,'092E09'x);
  end;
  input (var1-var8) ($);
  datalines;
2	"28 	4					29"	
;
run;

Art, CEO, AnalystFinder.com

View solution in original post

16 REPLIES 16
Ksharp
Super User
data ds2;
infile datalines ;
input;
var1=scan(_infile_,1,'|','m');
var2=scan(_infile_,2,'|','m');
var3=scan(_infile_,3,'|','m');
var4=scan(_infile_,4,'|','m');
var5=scan(_infile_,5,'|','m');
var6=scan(_infile_,6,'|','m');
var7=scan(_infile_,7,'|','m');
var8=scan(_infile_,8,'|','m');

datalines;
2|"28 |4|||||29" |
run;

proc print data=ds2;
run;
ballardw
Super User

If your data does not contain any Pipe characters as part of the actual data then you probably do not need DSD to read it.

If you data is not pipe delimited then you should indicate how the data is actually structured.

 

 

Kurt_Bremser
Super User

@ballardw the problem comes from the dual function of dsd; one needs dsd so that two or more successive delimiters are read as missing values. But then SAS also drops the quotes.

atul_desh
Quartz | Level 8
yup.. is there any way so that dsd don't consider double quotes & single quotes as delimiter and only consider Pipe or '09'x ??
atul_desh
Quartz | Level 8
My data is in tab delimited text file... but I shown here as pipe delimited just to more readable.
art297
Opal | Level 21

The following should work:

data ds2;
  infile datalines dsd dlm="|" missover;
  input @;
  _infile_=translate(_infile_,'~','"');
  input (var1-var8) ($);
  array have(*) $ var1-var8;
  do i=1 to dim(have);
    have(i)=translate(have(i),'"','~');
  end;
datalines;
2|"28 |4|||||29" |
run;

Art, CEO, AnalystFinder.com

atul_desh
Quartz | Level 8
thank you but Actual data which I'm having is having 180 variable and 85 million observation.. so using array make them more difficult to run...longer to run.
art297
Opal | Level 21

Do you need to keep the quotation marks? If not, the array isn't needed as they could just be compressed rather than converted to a tilde.

 

Art, CEO, AnalystFinder.com

atul_desh
Quartz | Level 8
Yes I do need quotation mark !! 😞
art297
Opal | Level 21

Then you could use:

data ds2;
infile datalines dlm="|" missover;
input @;
do while (index(_infile_,'||') gt 0);
_infile_=tranwrd(_infile_,"||","|.|");
end;
input (var1-var8) ($);
datalines;
2|"28 |4|||||29" |
;
run;

Art, CEO, AnalystFinder.com

atul_desh
Quartz | Level 8
In Actaul file it is tab delimeted... I'm trying to replace | with '09'x..
art297
Opal | Level 21

My original code had an uncorrected oversight which I'll correct after posting this. The following will work with your tab delimited file:

data ds2;
  infile datalines dlm='09'x missover;
  input @;
  do while (index(_infile_,'0909'x) gt 0);
    _infile_=tranwrd(_infile_,'0909'x,'092E09'x);
  end;
  input (var1-var8) ($);
  datalines;
2	"28 	4					29"	
;
run;

Art, CEO, AnalystFinder.com

atul_desh
Quartz | Level 8

@art297 I'm getting issue when my first column is blank...even though i've tried missover, truncover but issue still persist. 

Tom
Super User Tom
Super User

@atul_desh wrote:

@art297 I'm getting issue when my first column is blank...even though i've tried missover, truncover but issue still persist. 


Add code to handle that case.

if _infile_=: '09'x then _infile_='.'||_infile_;

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
  • 16 replies
  • 1925 views
  • 3 likes
  • 6 in conversation