BookmarkSubscribeRSS Feed
tejeshwar
Calcite | Level 5
Hi,

GoodMorning!
I am trying to create a Tab dlm file using the file statement.

Currently below is the code I am using
data _null_;
set A;
file 'D:\final.txt' delimiter ='09'X ;
put acct scr ;
run;

My objective is to achieve 2 things
1) Have a header, meaning coloumn names in the first row, using the above only the data is copied.
2) I want scr to be right justified, is this possible.

Appreciate any help!

Regards,
Tejeshwar
7 REPLIES 7
Doc_Duke
Rhodochrosite | Level 12
To add a header, include this line above the first put statement:

PUT 'acct'||'09'x||'scr';

I think (untested) that you can get scr to be right justified by using a $char format for it, as in

FORMAT scr $char5.;
tejeshwar
Calcite | Level 5
Thanks.
Tried the below, SAS throwed an error.

data _null_;
set A;
file 'D:\final.txt' delimiter ='09'X ;
put 'acct'||'09'x||'scr';
put acct scr ;
run;

--
22
-----
200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, arrayname,
#, (, +, /, //, ;, @, @@, OVERPRINT, _ALL_, _BLANKPAGE_, _ODS_, _PAGE_.

ERROR 200-322: The symbol is not recognized and will be ignored.


Also, If I just put put 'acct' in the first line, SAS is populating this btw each observation of data, something like

acct
123432133 323
acct
432233243 322

Regards
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The PUT statement does not call for a concatenation nor an explicit delimiter, since you have the DLM= coded on the FILE statement. And you will want to review the DSD option on the FILE statement.

Also, if you have no data for the input file, you will have no header row, either. You will want to code the header row PUT statement ahead of the SET statement to ensure at least a header row is generated.

Scott Barry
SBBWorks, Inc.
tejeshwar
Calcite | Level 5
Thanks Scott.
I managed to write the below code and it accomplishes one of the objectives to get the header for this file but I still cant get Nw_L to right-justify in the output file

data _null_;
set WORK.AB end=EFIEOD;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
%let _EFIREC_ = 0; /* clear export record count macro variable */
file 'D:\ab.txt' delimiter='09'x DSD DROPOVER
lrecl=32767;
format ACCT $20. ;
format AB_ID $10. ;
format CY_CD best12. ;
format Nw_L $7. ;
format Type $1.;
if _n_ = 1 then /* write column names */
do;
put
'ACCT'
'09'x
'AB_ID'
'09'x
'CY_CD'
'09'x
'Nw_L'
'09'x
'Type'


;
end;
do;
EFIOUT + 1;
put ACCT $ @;
put AB_ID $ @;
put CY_CD @;
put Nw_L @;
put Type $ ;

;
end;
if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
if EFIEOD then call symputx('_EFIREC_',EFIOUT);
run;

Any thoughts as to if/how we can accomplish that?

Regards,
Tejeshwar

Message was edited by: tejeshwar Message was edited by: tejeshwar
Doc_Duke
Rhodochrosite | Level 12
try this, then.

IF _N_ =1 THEN PUT 'accr' 'scr';

The "IF _n_=1 THEN" clause will put out the row only once.
DanielSantos
Barite | Level 11
You should override the default alignment for the put statement (in your case -R option).

put -;

for example: put X $10 -R; /* x right aligned in a 10 char space */

Please, check online documentation here:
http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000175758.htm

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
tejeshwar
Calcite | Level 5
Thanks Daniel,

This actually works in terms of right-justify but gives me some problem with the attribute after that attribute
ex: if the data was
acct scr type
123432 234 B
323246 36 C

Now after right justifying scr, it becomes like
acct scr type
123432 234B
323246 36C

It seems its not able to create a tab dlm between the attribute which is right justify and the next value
Any suggestions?

Message was edited by: tejeshwar Message was edited by: tejeshwar

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 908 views
  • 0 likes
  • 4 in conversation