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?
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;
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?
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!
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;
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
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
I think I have it!
It's the
termstr=CRLF.
When I delete that it runs.
Thanks for all the help.
Barbara
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.