DATA Step, Macro, Functions and more

adding period

Accepted Solution Solved
Reply
Contributor
Posts: 62
Accepted Solution

adding period

hello,

 I have this data and need to to add a period to the ID variable  to get  to this result "data want"

Any thoughts? thank you.

 

 

data have;

Id;

datalines

ID
40300
Z01
U900
303037
Z110112
917
3039
L303936
U30501
R00
305
U307G7

;

 

 

data want

ID
403
Z01
U90.0
303.037
Z11.0112
917
303.9
L30.3936
U30.501
R00
305
U30.7G7

Accepted Solutions
Solution
‎11-22-2016 10:30 AM
Trusted Advisor
Posts: 1,554

Re: adding period

Posted in reply to archibald

What is the logic (rules) for adding the period ?

Is it adding after the 3rd character in case of more than 3 characters ?

 

then:

      data want;

       set have;

           if length(strip(ID)) > 3 then 

             ID  = catx('.', substr(ID,1,3) , substr(ID,4));

      run;

View solution in original post


All Replies
Solution
‎11-22-2016 10:30 AM
Trusted Advisor
Posts: 1,554

Re: adding period

Posted in reply to archibald

What is the logic (rules) for adding the period ?

Is it adding after the 3rd character in case of more than 3 characters ?

 

then:

      data want;

       set have;

           if length(strip(ID)) > 3 then 

             ID  = catx('.', substr(ID,1,3) , substr(ID,4));

      run;

PROC Star
Posts: 1,759

Re: adding period

Or even:

data WANT;
  set HAVE;
  ID = catx('.', substr(ID,1,3) , substr(ID,4));
run;

Contributor
Posts: 62

Re: adding period

Another great solution. Thank you!!

Contributor
Posts: 62

Re: adding period

This is absolutely perfect! Thank you very much!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 164 views
  • 3 likes
  • 3 in conversation