BookmarkSubscribeRSS Feed
wentao
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?

 

 

3 REPLIES 3
ballardw
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.

wentao
Calcite | Level 5

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.

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

sas-innovate-2024.png

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.

 

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