Hi All,
I'm trying to export a SAS dataset to a text file using the SAS labels as headers in my text file. i've specified the label option but I still get variable names instead. here is an example of what i'm doing and the results i get:
data Have;
input X Y 1. ;
label x = "X Label" y = "Y Label";
cards;
1 3
2 4
;
run;
PROC EXPORT DATA= Have
OUTFILE= "E:\Jeff B\Open\Want.txt"
DBMS=DLM REPLACE;
DELIMITER='7C'x;
PUTNAMES=YES;
Label; /* variable names print despite label option being specified */
RUN;
Here is the log, you can see that the "PUT" statment is still using variable names.
347 data Have;
348 input X Y 1. ;
349 label x = "X Label" y = "Y Label";
350 cards;
NOTE: The data set WORK.HAVE has 2 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
353 ;
354 run;
355
356 PROC EXPORT DATA= Have
357 OUTFILE= "E:\Jeff B\Open\Want.txt"
358 DBMS=DLM REPLACE ;
359 Label;
360 DELIMITER='7C'x;
361 PUTNAMES=YES;
362 RUN;
363 /**********************************************************************
364 * PRODUCT: SAS
365 * VERSION: 9.2
366 * CREATOR: External File Interface
367 * DATE: 07AUG12
368 * DESC: Generated SAS Datastep Code
369 * TEMPLATE SOURCE: (None Specified.)
370 ***********************************************************************/
371 data _null_;
372 %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
373 %let _EFIREC_ = 0; /* clear export record count macro variable */
374 file 'E:\Jeff B\Open\Want.txt' delimiter='|' DSD DROPOVER lrecl=32767;
375 if _n_ = 1 then /* write column names or labels */
376 do;
377 put
378 "X"
379 '|'
380 "Y"
381 ;
382 end;
383 set HAVE end=EFIEOD;
384 format X best12. ;
385 format Y best12. ;
386 do;
387 EFIOUT + 1;
388 put X @;
389 put Y ;
390 ;
391 end;
392 if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
393 if EFIEOD then call symputx('_EFIREC_',EFIOUT);
394 run;
NOTE: The file 'E:\Jeff B\Open\Want.txt' is:
Filename=E:\Jeff B\Open\Want.txt,
RECFM=V,LRECL=32767,File Size (bytes)=0,
Last Modified=07Aug2012:12:21:50,
Create Time=07Aug2012:12:15:44
NOTE: 3 records were written to the file 'E:\Jeff B\Open\Want.txt'.
The minimum record length was 3.
The maximum record length was 3.
NOTE: There were 2 observations read from the data set WORK.HAVE.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
2 records created in E:\Jeff B\Open\Want.txt from HAVE.
NOTE: "E:\Jeff B\Open\Want.txt" file was successfully created.
NOTE: PROCEDURE EXPORT used (Total process time):
real time 0.07 seconds
cpu time 0.07 seconds
add the label statement into your proc export statement instead, before the DBMS keyword:
PROC EXPORT DATA= Have
OUTFILE= "C:\temp\Want.txt"
label DBMS=DLM REPLACE ;
add the label statement into your proc export statement instead, before the DBMS keyword:
PROC EXPORT DATA= Have
OUTFILE= "C:\temp\Want.txt"
label DBMS=DLM REPLACE ;
Thanks Reeza.
I wonder why in my code label is blue, but in your code (the correct way) its not, just seems counter-intuitive?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.