- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Can you provide an example of the character variable value that you want to convert?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I've attached the proc freq of the charvar
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I've attached the proc freq of the charvar
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Do you know what date the character value eg '42062' is to be interpreted as?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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