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

Hi all, 

 

i am working on SAS 9.4 version. I need help on changing the values of a variable. 

I have to replace asset1 with 2000, asset2 with 2001, asset3 with 2002 and so on. it is unbalanced panel data of around 5000 companies with 19 years of time series observations from the year 2000 to 2018 My data set is like as follows. 

 

company   variable 

A                asset1
A             asset2
A              asset3
Aasset4
Basset1
Basset2
Basset3
Casset1
Casset2
Casset3
Casset4
Dasset1
Dasset2
Dasset3

Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
srikanthyadav44
Quartz | Level 8

thanks a lot. the code is working excellently. 

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

Welcome to the SAS Community 🙂

 

data have;
input company $ variable $;
datalines;
A asset1
A asset2
A asset3
A asset4
B asset1
B asset2
B asset3
C asset1
C asset2
C asset3
C asset4
D asset1
D asset2
D asset3
;

data want;
    set have;
    newvar=sum(input(compress(variable, '', 'kd'), 8.), 1999);
run;
srikanthyadav44
Quartz | Level 8

thanks a lot. the code is working excellently. 

srikanthyadav44
Quartz | Level 8

dear 

can you please tell me know to change the code when i have 25 observations for each company?

thanks in advance 

srikanthyadav44
Quartz | Level 8

yes. I tried. but all the observations of each  company are getting the value of '1999' only. 

my data starts at the year 1994 and ends at 2018. 

Kindly help me in changing the  previously used code to get the desired output. 

thanks in advance

Kurt_Bremser
Super User

Since @PeterClemmensen 's code DOES work (just run it), your data must be different than what you showed in your initial post. Please post correct example data in a data step with datalines, as seen in @PeterClemmensen 's post.

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 25. 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
  • 7 replies
  • 1280 views
  • 0 likes
  • 3 in conversation