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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.