Help using Base SAS procedures

a question on tranwrd

Reply
Frequent Contributor
Posts: 102

a question on tranwrd

i have ran a code:

data us99;

set us13;

annualreportdate=tranwrd(annualreportdate,'Dec','');

run;

for some strange reason, after i get rid of Dec, I get a space between my year ie: (space)2013

how can i remove that space so that the ones that i removed Dec aligns with other year observations?

thank you!

Super User
Posts: 19,770

Re: a question on tranwrd

I think there's better ways to do what you want to do...but you need to provide more details.

You can use compress to remove spaces to solve your immediate problem. 

Trusted Advisor
Posts: 1,137

Re: a question on tranwrd

In case you would like to remove the character data from the variable, you can try the below code

data have;

    annualreportdate='01Dec2013';

annualreportdate=compress(annualreportdate,,'kd');

run;

Thanks,

Jag

Thanks,
Jag
Valued Guide
Posts: 2,177

Re: a question on tranwrd

annualreportdate=tranwrd(annualreportdate,'Dec','');

for some strange reason, after i get rid of Dec, I get a space between my year ie: (space)2

how can i remove that space

AnnualReportDate = tranwrd( annualreportdate, 'Dec2', '2' ) ;

You might need to repeat it for the 1900s if your reports go that far back (but that seems less likely)

Super User
Posts: 10,020

Re: a question on tranwrd

Use another function.

data us99;
annualreportdate='Dec2014';
annualreport=prxchange('s/Dec//',-1,annualreportdate);
run;

Xia Keshan

Respected Advisor
Posts: 3,799

Re: a question on tranwrd

To replace to null string, length 0, you need "new" TRANSTRN function and to specify a 0 length string you need a function like TRIMN.

data _null_;
  
x = '18DEC2013';
   a = tranwrd(x,
'DEC',trimn(' '));
   b = tranSTRN(x,'DEC',trimn(' '));
   put 'NOTE: ' (_all_)(=);
   run;

NOTE:
x=18DEC2013 a=18 2013 b=182013
Ask a Question
Discussion stats
  • 5 replies
  • 232 views
  • 0 likes
  • 6 in conversation