BookmarkSubscribeRSS Feed
Calcite | Level 5

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?



Super User

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.

Calcite | Level 5

libname library 'c:\';

filename final 'c:\final_out.txt';
proc export data=library.test
dbms=csv replace;



data _null_;
      infile "c:\final_out.txt" firstobs=2;
set library.test;
      file "c:\final_out.txt";
put _infile_;


That's my code.


But the first row of results still have headers for every variables. And all values are missing quotation marks.

Super User

@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.

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
  • 3 replies
  • 2 in conversation