Hello SAS experts,
I am trying to read an external text file but my code does not work. any help is appreciated
this is what I am trying to read from:
New/Additional Parameters
L1_0 -1.682 0.342 -4.911 0.000
L1_11 2.310 0.370 6.251 0.000
L2_0 -1.522 0.280 -5.433 0.000
L2_12 2.009 0.281 7.144 0.000
L3_0 -2.238 0.430 -5.202 0.000
L3_12 1.689 0.351 4.813 0.000
L3_13 2.228 0.346 6.430 0.000
L4_0 -1.167 0.211 -5.544 0.000
L4_11 1.825 0.368 4.957 0.000
L5_0 -1.796 0.359 -4.999 0.000
L5_11 1.452 0.536 2.709 0.007
L5_13 1.915 0.491 3.897 0.000
L6_0 -1.995 0.504 -3.961 0.000
L6_11 1.516 1.194 1.269 0.204
L6_12 2.161 0.717 3.015 0.003
L7_0 -3.626 0.550 -6.597 0.000
L7_11 2.524 0.550 4.593 0.000
this is my code:
data CDM.temp_&seed;
infile "c:\cdm\&commandfile..out" truncover end=finished;/***********/
input test $21. @;
if trim(test)="New/Additional Parameters" then do;
input / @20 L1_0
/ / @20 L3_0
/ / L3_0
/ / / L4_0
/ / L5_0
;
output;
stop;
end;
drop test;
run;
proc print;run;
figured it out. This is how:
data CDM.temp_&seed;
infile "c:\cdm\&commandfile..out" truncover;
input test $27. @; /* 27= the lenght of New/Additional Parameters*/
if trim(test)="New/Additional Parameters" then do;
input / @23 L1_0
/ / @23 L2_0
/ / @23 L3_0
/ / / @23 L4_0
/ / @23 L5_0
/ / @23 L6_0
/ / / / @23 L7_0
;
output;
stop;
end;
drop test;
run;
Yes, it does look like you figured out how to read that particular file. But it seems that your data can vary, so you need a little flexibility. Since you seem to only want to keep tests that end in '_0' then the following code will allow you to check each test instead of using hardcoded line breaks which may fail you the next time you have to run it. The transposition creates the final dataset using the names of the test as the names of the variables
data temp;
infile 'c:\temp\commandfile.out' firstobs=2;
input test $ @;
if scan( test, -1, '_' ) = '0' then do;
input parm;
output;
end;
run;
proc transpose data=temp out=temp;
id test;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.