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

I am using SAS EG 7.15 on Linux using SAS 9.4. For example:

 

data _NULL_;

set in;

file '////out.csv' delimiter=",";

if _n_=1 then put "var1, var2, etc";

put var1, var2, etc;

run;

 

data new;

infile '////out.csv' dlm="," dsd missover firstobs=2 termstr=CLRF;

input var1, var2, etc;

run;

 

The second data step cannot read the records created in the first data step.

 

NOTE: 0 records were read from the infile '////out.csv' .
NOTE: The data set WORK.NEW has 0 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

 

How do we work around this?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Commas in the PUT statement for one. Picking a location you know you have access to, does this work for you?

 

data _NULL_;

set sashelp.class;

file 'C:\_localdata\temp\out.csv' delimiter=",";

if _n_=1 then put "name, age, sex";

put name age sex;

run;

 

data new;

infile 'C:\_localdata\temp\out.csv' dlm="," dsd missover firstobs=2;

input name $ age sex $;

run;

View solution in original post

6 REPLIES 6
Reeza
Super User

Is the code you ran the code you posted?

It's incorrect, the log should have errors? Or post the actual code or a reproducible example.

The premise is correct and this type of logic can work.

 


@bwilsonrelyea wrote:

I am using SAS EG 7.15 on Linux using SAS 9.4. For example:

 

data _NULL_;

set in;

file '////out.csv' delimiter=",";

if _n_=1 then put "var1, var2, etc";

put var1, var2, etc;

run;

 

data new;

infile '////out.csv' dlm="," dsd missover firstobs=2 termstr=CLRF;

input var1, var2, etc;

run;

 

The second data step cannot read the records created in the first data step.

 

NOTE: 0 records were read from the infile '////out.csv' .
NOTE: The data set WORK.NEW has 0 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

 

How do we work around this?


 

 

bwilsonrelyea
Calcite | Level 5

There were no error messages. This is just a simplified example. What do I have incorrect other than the etc?

 

I have used many was to create and read a csv file in one program run, including proc import/export and the %ds2cvs macro. No method works. I have to physically go to the file and open the new csv and save it before executing the next statement to read it.

 

Thanks!

Reeza
Super User

Commas in the PUT statement for one. Picking a location you know you have access to, does this work for you?

 

data _NULL_;

set sashelp.class;

file 'C:\_localdata\temp\out.csv' delimiter=",";

if _n_=1 then put "name, age, sex";

put name age sex;

run;

 

data new;

infile 'C:\_localdata\temp\out.csv' dlm="," dsd missover firstobs=2;

input name $ age sex $;

run;
bwilsonrelyea
Calcite | Level 5

Thank you Reeza. This does work. I do not have commas in a put statement in my real code - sorry. I still do not know why my code does not work. It could be because both parts are inside a macro, or that the file name and variable lists are macro variables - but that does not seem likely. I'll investigate some more. It's good to know that it actually works though.

 

NOTE: 19 records were read from the infile '/////out.csv'.

The minimum record length was 9.

The maximum record length was 12.

NOTE: The data set WORK.NEW has 19 observations and 3 variables.

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.00 seconds

 

Reeza
Super User

Your example has single quotes, macro variables will only resolve in double quotes but without seeing the code it's anyone's guess.

 


@bwilsonrelyea wrote:

Thank you Reeza. This does work. I do not have commas in a put statement in my real code - sorry. I still do not know why my code does not work. It could be because both parts are inside a macro, or that the file name and variable lists are macro variables - but that does not seem likely. I'll investigate some more. It's good to know that it actually works though.

 

NOTE: 19 records were read from the infile '/////out.csv'.

The minimum record length was 9.

The maximum record length was 12.

NOTE: The data set WORK.NEW has 19 observations and 3 variables.

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.00 seconds

 


 

bwilsonrelyea
Calcite | Level 5

I think I have it!

 

It's the

termstr=CRLF.

 

When I delete that it runs.

 

Thanks for all the help.

 

Barbara

 

 

 

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
  • 6 replies
  • 1065 views
  • 0 likes
  • 2 in conversation