BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I need to export this dataset to a txt file. while running this code, the data got exported , but am not getting headers like v1,v2..please let me know hoew to include headers ..

data vishal;
input v1 $1. v2 v3 v4 test&$20.;
cards;
a 1 2 3 test^it
b 4 5 6 test this
c 7 8 9 none
;
run;

data _null_;
set vishal;
file 'C:\Documents and Settings\\Desktop\vishal.txt' DLM=',';
put ( _all_ ) (~);
run;

Thanks in Advance !!!
7 REPLIES 7
garybald
Calcite | Level 5
before your put statement, try this

if _n_ = 1 then do;
put 'v1' '~'
'v2' '~'
etc.
end;
deleted_user
Not applicable
Hi Gary ,

I tried as below.. its not working ..

data _null_;
set vishal;
file 'C:\Documents and Settings\Desktop\vishal.txt' DLM=',';
if _n_ = 1 then do;
put 'v1' '~' 'v2' '~';
put ( _all_ ) (~);
run;
deleted_user
Not applicable
Yes Gary Its worked out !!!
I missed the end statement ..

ThankYou !!
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Raveenat,

Try to use the proc EXPORT like this:
[pre]
proc export DATA=Vishal
OUTFILE='C:\Documents and Settings\\Desktop\vishal.xls'
DBMS=CSV REPLACE;
run;
[/pre]
Sincerely,
SPR
deleted_user
Not applicable
Yes SPR.. I tried proc export (need to export it as text file) too but am not getting variables on proper order.
Please suggest me how to get an variables on proper order ?
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Raveenat,

It looks like we move in circles. To order variables use a datastep with retain before set, then export. For example;
[pre]
data r;
retain A,B,C;
set i;
run;
[/pre]
Dataset r has variables in the order A, B, C irrelevant to their order in i.
Sincerely,
SPR
deleted_user
Not applicable
Thanks SPR !! Its perfect now !!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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