BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
archibald
Obsidian | Level 7

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
1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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

4 REPLIES 4
Shmuel
Garnet | Level 18

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;

ChrisNZ
Tourmaline | Level 20

Or even:

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

archibald
Obsidian | Level 7

Another great solution. Thank you!!

archibald
Obsidian | Level 7

This is absolutely perfect! Thank you very much!

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 2031 views
  • 3 likes
  • 3 in conversation