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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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
  • 565 views
  • 2 likes
  • 2 in conversation