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 !!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1942 views
  • 0 likes
  • 3 in conversation