Help using Base SAS procedures

Header

Reply
N/A
Posts: 0

Header

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 !!!
Contributor
Posts: 29

Re: Header

Posted in reply to deleted_user
before your put statement, try this

if _n_ = 1 then do;
put 'v1' '~'
'v2' '~'
etc.
end;
N/A
Posts: 0

Re: Header

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;
N/A
Posts: 0

Re: Header

Posted in reply to deleted_user
Yes Gary Its worked out !!!
I missed the end statement ..

ThankYou !!
Super Contributor
Super Contributor
Posts: 365

Re: Header

Posted in reply to deleted_user
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
N/A
Posts: 0

Re: Header

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 ?
Super Contributor
Super Contributor
Posts: 365

Re: Header

Posted in reply to deleted_user
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
N/A
Posts: 0

Re: Header

Thanks SPR !! Its perfect now !!
Ask a Question
Discussion stats
  • 7 replies
  • 174 views
  • 0 likes
  • 3 in conversation