Hi, I am new to SAS and I am just doing a simple practise now.
Say now I have a txt raw data file looks like this:
"ABDSADJFASF",6,7,"SDDASDJASD", 12/12/2012, "ASDSDADASD",0.0,0.0.0
"FGHJKJHGGHJK",6,7,"SUUNSDHDHH", 11/12/2009, "AFSDFDGDSGSD",0.0,0.0.0
...
I can read in all the vars by set them all as char(using :&) and then output the dataset with exactly the values between dlm ',' (ie. some values with quotes and some don't).
But how can I convert the dataset back to another txt file, which should be exacly like the raw txt file?
I was using proc export but I can't use putnames statement since my version is 9.1, any workaround?
Is the purpose to manipulate the data and create output or to create an exact duplicate of the input text file?
If the later case then look at PUT _infile_; with the new file name in a FILE statement in the data step you read the file with.
libname library 'c:\';
filename final 'c:\final_out.txt';
proc export data=library.test
outfile="c:\final_out.txt"
dbms=csv replace;
run;
data _null_;
infile "c:\final_out.txt" firstobs=2;
set library.test;
file "c:\final_out.txt";
input;
put _infile_;
run;
That's my code.
But the first row of results still have headers for every variables. And all values are missing quotation marks.
@wentao wrote:
That's my code.
But the first row of results still have headers for every variables. And all values are missing quotation marks.
I see nothing in your post about not wanting the header row only that you couldn't use the putnames statement.
if _n_ > 1 then put _infile_;
will write other than the header rows.
It appears that you may have destroyed your orginal file by using proc export to write over it. Proc Exported removed any quotes that did not need quotes.. Quotes around a single word or phrase with no embedded commas in CSV are not needed and were likely replaced by Export, not by the PUT _INFILE_ which would keep the quotes. Then rereading the file that had the quotes removed means they are not there to write with a PUT statement.
Also, did you open that CSV with Excel or a text editor such as Wordpad or Notepad? Excel will not show the quotes generally. And may remove those that are there if you save the file.
Your data _null_ program does not need the SET statement.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.