Hi All,
I have a SAS table with 8 columns, the last 2 of which are Permno and Eventdat. I am looking to add a 9th column that takes the data within the Permno Column and concatenates it with the data in the Eventdat Column with a "-" in between. I found another post on the topic that was older but it didn't appear to work for me. Here is the code I currently have. If possible I would also like to strip out any leading and trailing blanks.
I've also tried putting "permno" and "eventdat" in quotes but then it just shows up as words. My other variables disappear too!
data temp.biotechControlsFinal;
var1 = Permno;
var2 = Eventdat;
length var3 $ 15;
var3 = catx('-', var1, var2);
put _all_;
run;
You need to tell the data step where to find the original data. Also use your variables names. Make sure to make the new variable, VAR3 in code below, long enough. You probably don't want to overwrite your original dataset, so make a new one.
data want ;
set temp.biotechControlsFinal;
length var3 $ 15;
var3 = catx('-', Permno, Eventdat);
run;
Also if EVENTDAT is a date you might need to add a PUT() function to convert it to the string you want to use in the new variable instead of the raw number of days since 1960 that SAS uses to store dates.
data want ;
set temp.biotechControlsFinal;
length var3 $ 30;
var3 = catx('-', Permno, put(Eventdat,yymmdd10.));
run;
You need to format your dates, but it should work otherwise.
var3 = catx('-', put(var1, date11.), put(var2, date11.));
If that doesn't work please show the log and indicate what is occurring, in detail. "Not working" is vague and doesn't provide very much information on what is or is not working.
@anweinbe wrote:
Hi All,
I have a SAS table with 8 columns, the last 2 of which are Permno and Eventdat. I am looking to add a 9th column that takes the data within the Permno Column and concatenates it with the data in the Eventdat Column with a "-" in between. I found another post on the topic that was older but it didn't appear to work for me. Here is the code I currently have. If possible I would also like to strip out any leading and trailing blanks.
I've also tried putting "permno" and "eventdat" in quotes but then it just shows up as words. My other variables disappear too!
data temp.biotechControlsFinal;
var1 = Permno;
var2 = Eventdat;
length var3 $ 15;
var3 = catx('-', var1, var2);
put _all_;
run;
You need to tell the data step where to find the original data. Also use your variables names. Make sure to make the new variable, VAR3 in code below, long enough. You probably don't want to overwrite your original dataset, so make a new one.
data want ;
set temp.biotechControlsFinal;
length var3 $ 15;
var3 = catx('-', Permno, Eventdat);
run;
Also if EVENTDAT is a date you might need to add a PUT() function to convert it to the string you want to use in the new variable instead of the raw number of days since 1960 that SAS uses to store dates.
data want ;
set temp.biotechControlsFinal;
length var3 $ 30;
var3 = catx('-', Permno, put(Eventdat,yymmdd10.));
run;
Tom,
The Eventdat is currently a Date9. An example of my data is 15FEB2017. Is there a way to keep it just as is?
So if my Permno is 12345 and the date is 15FEB2017, the result should will be 12345-15FEB2017
I tried both of what you sent but it converts the date. You noted that above. Is there an easy way to fix that?
The date part will only play any role in the sorting (if you even ever need to sort) would be when there are multiple dates for the same value of the prefixed variable.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.