BookmarkSubscribeRSS Feed
sasuser143
Calcite | Level 5

Data set have :

id 

PBVS1

PBVS2 

PBVS3

PBVS4

PBVS5

PBVS6

PBVS7

PBVS7A

PBVSTOT1

 

I want data :

id

PBVS101

PBVS102

PBVS103

PBVS104

PBVS105

PBVS106

PBVS107

PBVS107A

PBVS111

 

 

1 REPLY 1
ballardw
Super User

Is there a generic rule that can be applied to know that PBVSTOT1 should become PBVS111?

 

This works for the shown data but you may need to provide some RULES if any other values are involved.

Note the use of a data step to provide example data. That is what you should do to set the properties of YOUR variables to be correct for your problem.

Data have ;
   input id $ ;/* note this defaults to 8 character length*/
datalines;
PBVS1
PBVS2 
PBVS3
PBVS4
PBVS5
PBVS6
PBVS7
PBVS7A
PBVSTOT1
;


data want;
   set have;
   if index(id,'TOT')>0 then Id='PBVS111';
   else id = tranwrd(id,'PBVS','PBVS10');
run;

The Tranwrd function will replace in the value of the first parameter  the first group of characters , i.e. a word, with another .

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 347 views
  • 2 likes
  • 2 in conversation