BookmarkSubscribeRSS Feed
aarony
Obsidian | Level 7

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!

5 REPLIES 5
Reeza
Super User

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. 

Jagadishkatam
Amethyst | Level 16

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
Peter_C
Rhodochrosite | Level 12

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)

Ksharp
Super User

Use another function.

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

Xia Keshan

data_null__
Jade | Level 19

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 797 views
  • 0 likes
  • 6 in conversation