I've got a variable whose values are either blank or a 5 digit number that SAS is reading as a character. When I do proc contents for this var, tells me it's type char, format $5. This 5 digit number should actually correspond to a date, so I want to convert it to numeric then I can format it as a date.
What I've tried to do:
data new; set old; numVar=input(charVar, 5.); run;
If I do proc contents of the new dataset, it tells me that it's still a character var with len 5. Format/informat are blank. What am I doing wrong??
Thank you!
Can you provide an example of the character variable value that you want to convert?
I've attached the proc freq of the charvar
I've attached the proc freq of the charvar
Do you know what date the character value eg '42062' is to be interpreted as?
@KPCklebspn wrote:
I've attached the proc freq of the charvar
Looks like a typical Excel date to SAS date conversion. If your data started in Excel then the issue is how you brought the data into SAS, and possibly what has been done since.
So, did this data start in Excel? If so please describe how you brought it into SAS.
Your code works perfectly for me:
data old;
charVar = '21635';
output;
run;
proc sql;
select * from dictionary.columns where libname="WORK" and memname="OLD";
run;
data new;
set old;
numVar=input(charVar, 5.);
run;
proc sql;
select * from dictionary.columns where libname="WORK" and memname="NEW";
run;
Wednesday, 27 March, 2019 10:53:00 AM 1 Column Library Member Column Column Column Number Name Member Name Type Column Name Type Length Position in Table Column Index Column Label Column Format Column Informat Type Order in Key Extended Not Sequence Type NULL? Precision Scale Transcoded? ------------------------------------------------------------------------------------------------------------------------------------ WORK OLD DATA charVar char 5 0 1 0 char no 0 . yes Wednesday, 27 March, 2019 10:53:00 AM 2 Column Library Member Column Column Column Number Name Member Name Type Column Name Type Length Position in Table Column Index Column Label Column Format Column Informat Type Order in Key Extended Not Sequence Type NULL? Precision Scale Transcoded? ------------------------------------------------------------------------------------------------------------------------------------ WORK NEW DATA charVar char 5 8 1 0 char no 0 . yes WORK NEW DATA numVar num 8 0 2 0 num no 0 . yes
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.