The SAS Output Delivery System and reporting techniques

How to use labels in proc export or create tab dlm file using proc print

Reply
Occasional Contributor
Posts: 9

How to use labels in proc export or create tab dlm file using proc print

I need to create a tab dlm file out of a sas dataset with label names.

So if I can achieve either of the following it would work.

a. I am able to get the labels using proc print but tab delimited is a problem.
b. I am able to create tab delimited using proc export but getting the labels is a problem.

Would request sas gurus to help me out.

Regards
Super Contributor
Super Contributor
Posts: 3,174

Re: How to use labels in proc export or create tab dlm file using proc print

SAS-supplied macro %DS2CSV can generate such an output.

Scott Barry
SBBWorks, Inc.
SAS Super FREQ
Posts: 8,743

Re: How to use labels in proc export or create tab dlm file using proc print

Hi:
Also,
[pre]
ODS CSV FILE='xxxxxx.csv';
proc print data=sashelp.class label;
run;
ODS CSV CLOSE:
[/pre]

will do what you want.

cynthia
Super Contributor
Super Contributor
Posts: 3,174

Re: How to use labels in proc export or create tab dlm file using proc print

I read the OP as wanting tab-delimited output, rather than comma-delimited. I looked briefly for some ODS CSV parameter option but found none.

Scott Barry
SBBWorks, Inc.
Occasional Contributor
Posts: 9

Re: How to use labels in proc export or create tab dlm file using proc print

Yes, Scott, The objective is to get a tab delimited file.

Thanks

w020637
SAS Super FREQ
Posts: 8,743

Re: How to use labels in proc export or create tab dlm file using proc print

Sorry for the incomplete answer. There is in 9.2, a delimiter= option that allows you to change the delimiter from a comma to a tab character (which is 09'x, I believe) for ODS CSV.

If you invoke this way, you will see what the options are:
[pre]
ods csv file='c:\temp\csvhelp.csv'
options(doc='Help');
[/pre]

Then the delimiter option goes in parens:
[pre]
ods csv file='c:\temp\tabhelp.txt'
options(doc='Help' delimiter="09"x);
proc print data=sashelp.class(obs=3) label;
run;
ods csv close;
[/pre]

cynthia
Respected Advisor
Posts: 3,777

Re: How to use labels in proc export or create tab dlm file using proc print

> There is in 9.2, a
> delimiter= option that allows you to change the
> delimiter from a comma to a tab character (which is
> 09'x, I believe) for ODS CSV.

That will be a nice feature. I look forward to using 9.2, soon perhaps.

The features of the FILE and PUT statement plus the call routine VNEXT make the data step solution fairly concise.

[pre]
filename FT24F001 temp lrecl=512;

data _null_;
file FT24F001 dsd dlm='09'x;
set sashelp.shoes(obs=3);
if _n_ eq 1 then link nameRow;
put (_all_)(Smiley Happy;
return;
nameRow:
length _LABEL_ $128 _NAME_ $32;
if _n_ eq 1 then do;
do while(1);
call vnext(_name_);
if _name_ eq '_LABEL_' then leave;
_label_ = vlabelx(_name_);
put _label_ @;
end;
put;
end;
return;
run;


data _null_;
infile FT24F001;
input;
list;
run;
[/pre]
Occasional Contributor
Posts: 9

Re: How to use labels in proc export or create tab dlm file using proc print

Hi guys,

I am using 9.1 and so the above solutions are not working for me. Appreciate the alacrity with which you guys have responded.

Regards

w020637
SAS Super FREQ
Posts: 8,743

Re: How to use labels in proc export or create tab dlm file using proc print

Hi:
I believe that you can download a copy of the CSV tagset template that will work for SAS 9.1.3 from this site:
http://support.sas.com/rnd/base/ods/odsmarkup/ (scroll down until you see the link for the CSV tagsets).

The SUGI paper that describes the OPTIONS suboption list and the DELIMITER suboption was written for SAS 9.1.3, so I believe you CAN get the delimiter, you just have to do some extra work because it's not included automatically with SAS (as it is in 9.2).
http://support.sas.com/rnd/base/ods/odsmarkup/p236-31.pdf

Although this note talks about installing and using the ExcelXP tagset template, the information about installing a tagset template and using the ODS PATH statement, also apply for updates to the CSV tagset template:
http://support.sas.com/kb/32/394.html

cynthia
Occasional Contributor
Posts: 9

Re: How to use labels in proc export or create tab dlm file using proc print

http://ftp.sas.com/techsup/download/sample/datastep/robust.html

helps to get the requirement

Regards

w020637
Respected Advisor
Posts: 3,777

Re: How to use labels in proc export or create tab dlm file using proc print

But my program does work in V9.1. You just assumed it would not work?
PROC Star
Posts: 1,561

Re: How to use labels in proc export or create tab dlm file using proc print

Sorry for reviving this thread, I got pointed to it from another thread.
data _null_, I like the simplicity of your data step, and the way you got around enumerating variables.
Fyi, I made a small macro out of it, for those (frequent) cases when tweaking the output is not needed.
[pre]

%macro write_CSV(fileref= /* REQD: export fileref */
,dataset= /* REQD: dataset name, including options if necessary */
,delimiter=',' /* OPTN: eg: '09'x and ' ' for tab and space */
,firstrow=LABEL /* OPTN: Values: LABEL or NAME or NONE */
,addquotes=SPECIALCHAR /* OPTN: Values: ALLVAR or ALLCHAR or SPECIALCHAR */
);
data _null_;
set &dataset;
file &fileref dlm=&delimiter %if %upcase(&addquotes) ne ALLCHAR %then dsd;;
%if %upcase(&addquotes)=ALLCHAR %then format _CHARACTER_ $quote.;;
%if %upcase(&firstrow) ne NONE %then if _N_ = 1 then link firstrow;;
put (_ALL_)(%if %upcase(&addquotes)=ALLVAR %then~;Smiley Happy;
length __LABEL__ $256 __NAME__ $32;
return;
firstrow:
do while( __NAME__ ne '__LABEL__' );
call vnext(__NAME__);
__LABEL__ = vlabelx(__NAME__);
if __NAME__ ne '__LABEL__' then put __%upcase(&firstrow)__ @;
else put;
end;
run;
%mend;
[/pre]
One question though: how come all PDV variables are not output when put (_ALL_) is run?
Super Contributor
Posts: 273

Re: How to use labels in proc export or create tab dlm file using proc print

Chris
Your macro must be completed
as in the case of an ALLCHAR choice there is an error

[pre]
file &fileref dlm=&delimiter %if %upcase(&addquotes) ne ALLCHAR %then dsd%str(Smiley Wink;
%else %str(Smiley Wink;
[/pre]

Andre from Paris ( not linked to any submarine activity ;-) )
PROC Star
Posts: 1,561

Re: How to use labels in proc export or create tab dlm file using proc print

Fixed, André, thank you.
I usually try to end my %if tests with a double ;; to remove %str() clutter, but I thought I'd post a more formal version... I have reverted to my old self now. That will teach me! Smiley Happy

Do you know why some PDV variables are not output when put (_ALL_) is run? I am still perplexed.
SAS Super FREQ
Posts: 8,743

Re: How to use labels in proc export or create tab dlm file using proc print

Chris:
I ran a much simpler test and found that the simple PUT _ALL_ writes out everything, including _N_ and _ERROR_, as shown below. If you're seeing something else, you might want to work with Tech Support or redo your macro to see if you can figure out where things might be going wrong.

cynthia
[pre]
data _null_;
set sashelp.shoes(obs=5);
file 'c:\temp\test_putall.txt';
format _CHARACTER_ $quote.;
format _NUMERIC_;
if _N_ = 1 then link firstrow;
put _ALL_;
return;
firstrow:
put 'What will be written out?';
return;
run;

Output:
What will be written out?
Region="Africa" Product="Boot" Subsidiary="Addis Ababa" Stores=12 Sales=29761 Inventory=191821 Returns=769 _ERROR_=0 _N_=1
Region="Africa" Product="Men's Casual" Subsidiary="Addis Ababa" Stores=4 Sales=67242 Inventory=118036 Returns=2284 _ERROR_=0 _N_=2
Region="Africa" Product="Men's Dress" Subsidiary="Addis Ababa" Stores=7 Sales=76793 Inventory=136273 Returns=2433 _ERROR_=0 _N_=3
Region="Africa" Product="Sandal" Subsidiary="Addis Ababa" Stores=10 Sales=62819 Inventory=204284 Returns=1861 _ERROR_=0 _N_=4
Region="Africa" Product="Slipper" Subsidiary="Addis Ababa" Stores=14 Sales=68641 Inventory=279795 Returns=1771 _ERROR_=0 _N_=5

[/pre]
Ask a Question
Discussion stats
  • 24 replies
  • 2350 views
  • 0 likes
  • 6 in conversation