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 |
A | asset4 |
B | asset1 |
B | asset2 |
B | asset3 |
C | asset1 |
C | asset2 |
C | asset3 |
C | asset4 |
D | asset1 |
D | asset2 |
D | asset3 |
Thank you in advance.
thanks a lot. the code is working excellently.
newvar = 1999 + input(substr(variable,6),best.);
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;
thanks a lot. the code is working excellently.
dear draycut
can you please tell me know to change the code when i have 25 observations for each company?
thanks in advance
Have you tried the code with 25 obs per company? If yes, where did the result not meet your expectations?
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
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.