BookmarkSubscribeRSS Feed
sas_Forum
Calcite | Level 5

But got it but i can do like that as we will run on a server .Can u do the same by infile <path>

Thqs

Ksharp
Super User

The file comma_data.txt is located in SAS Server?

If it were, let Administrator of SAS give your absolute path Like:  /home/myfile/comma_data.txt

and make sure you have privilege to read this file.

then use

filename x temp;

data _null_;

file x;

length row $ 400;

retain row;

infile '/home/myfile/comma_data.txt';

input;

row=cats(row,_infile_);

if countc(row,'"') ge 20 then do;put row; call missing(row);end;

run;

data want;

infile x dsd;

informat a b c d e f g h i j $200.;

input a$ b$ c$ d$ e$ f$ g$ h$ i$ j$  ;

run;

Ksharp

sas_Forum
Calcite | Level 5

ksharp can we cant do like this

data work;

length row $ 400;

retain row;

infile '/home/myfile/comma_data.txt';

input;

row=cats(row,_infile_);

if countc(row,'"') ge 20 then do;put row; call missing(row);end;

run;

data want;

infile work dsd;

informat a b c d e f g h i j $200.;

input a$ b$ c$ d$ e$ f$ g$ h$ i$ j$  ;

run;

art297
Opal | Level 21

Your code won't work because you created work as a sasfile, not a text file.  Did you try the method that Ksharp had proposed?

sas_Forum
Calcite | Level 5

It was working but can we do the way i have given

art297
Opal | Level 21

Short answer, no!  You could open 'work' with a set statement and then use the scan function to retrieve the delimited fields contained within the variable row.

But why would you, when Ksharp's proposed method is a lot cleaner and easier?

Ksharp
Super User

As Arthur said. You need to my whole original code .

filename x temp;

data _null_;

file x;

length row $ 400;

retain row;

infile '/home/myfile/comma_data.txt';

input;

row=cats(row,_infile_);

if countc(row,'"') ge 20 then do;put row; call missing(row);end;

run;

data want;

infile x dsd;

informat a b c d e f g h i j $200.;

input a$ b$ c$ d$ e$ f$ g$ h$ i$ j$  ;

run;

Ksharp

Ksharp
Super User

Why? Why do you have to make a dataset not a temporary file?

data work;
length row $ 400;
retain row;
infile 'c:\comma_data.txt';
input;
row=cats(row,_infile_);
if countc(row,'"') ge 20 then do;output; call missing(row);end;
keep row;
run;

data want;
 set work;
 a=scan(row,1,'"','m');
 b=scan(row,2,'"','m');
 c=scan(row,3,'"','m');
 d=scan(row,4,'"','m');
 e=scan(row,5,'"','m');
 f=scan(row,6,'"','m');
 g=scan(row,7,'"','m');
 h=scan(row,8,'"','m');
 i=scan(row,9,'"','m');
 j=scan(row,10,'"','m');
run;



Ksharp

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 22 replies
  • 1878 views
  • 1 like
  • 6 in conversation