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

I have a data set that has a character variable ($poc) and would like to replace it with 2 new variables: t (F2.0) and site ($2). Is that possible without the need to output to a raw data file and re-enter it? Thanks.

 

Have:

POC17DB

POC17BB

POC17MB

POC17ML

POC17LL

POC17DL

POC16DB

POC16BB

POC16MB

POC16ML

POC16LL

 

Want:

17 DB

17 BB

17 MB

17 ML

17 LL

17 DL

16 DB

16 BB

16 MB

16 ML

16 LL

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Peter_C
Rhodochrosite | Level 12
Have a look at the input() and substr() function documentation

View solution in original post

4 REPLIES 4
HB
Barite | Level 11 HB
Barite | Level 11

Will your data always be 

 

Three letters

Two numbers

Two letters

 

or can you have single digit or three digit numbers and single letter or three letter sites?

Jason2020
Obsidian | Level 7

Yes the data has a fixed format: 3 letters, 2 numbers, 2 letters

Peter_C
Rhodochrosite | Level 12
Have a look at the input() and substr() function documentation
Jason2020
Obsidian | Level 7

Thanks Peter. I solved it using the substr function:

 

  a = substr(site, 4, 2);
  b = substr(site, 6, 2);

 

Thanks again.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1239 views
  • 0 likes
  • 3 in conversation