BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello,

I have DATE as character variable (length 9) in the dataset "now_char" and the DATE column has dates like :- 22JAN2010 . I use the code:--

data combine;
set now_char;
if DATE LT "07JAN2010" THEN
Week = "Week1";
ELSE IF DATE GT "07/01/08" AND DATE LT "15/01Jan/08" THEN
Week = "Week2";
RUN;

Log:-

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
760:16 762:21 762:43
NOTE: Invalid numeric data, '27JAN2008' , at line 760 column 16.
NOTE: Invalid numeric data, '26/01/08' , at line 762 column 21.
NOTE: Invalid numeric data, '31/01Jan/08' , at line 762 column 43.

Any suggestions?

Kindest Regards,
Kriti
5 REPLIES 5
Proc_explode
Calcite | Level 5
Hi,

The easiest solution is to convert the character data (which is just a piece of text) into a SAS date (the number of days since 01JAN1960). To do this you need something like:

data combine;
set now_char;
if input(date,date9.) lt "07JAN2010"d then week = "Week1";
else if ....;
run;

Note that the d following the date in quotes inputes the text as a SAS date ("07JAN2010"d). I would have wrote out the whole data step but the dates in the second category don't appear to make any sense.

Hope that helps
art297
Opal | Level 21
I'm not sure what you are trying to do. If it is simply to count the number of seven day periods since January 1 of a given year, you could use something like:

data combine;
set now_char;
week=intck(cats('week.',
weekday(mdy(1,1,year(input(date,date9.))))),
mdy(1,1,year(input(date,date9.))),
input(date,date9.))+1;
run;

HTH,
Art
tlt
Obsidian | Level 7 tlt
Obsidian | Level 7
Hi,

Code and notes do not match
Notes say '27JAN2008' that can't be found in code.


NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column) 760:16 762:21 762:43
Look in your log, if you see something like 760 if DATE LT "..." THEN
It means your DATE is not a character variable

HTH
art297
Opal | Level 21
While I still don't know what you are trying to accomplish, I hadn't payed enough attention to the notes you indicated were in the SAS log.

Since your dates have an odd mixture of formats, again only if I correctly understand the problem, you might try something like:

data now_char;
input date $11.;
cards;
27JAN2008
26/01/08
31/01Jan/08
;
options datestyle=dmy;
data combine;
set now_char;
if anyalpha(scan(date,2))*anydigit(scan(date,2)) then
date=compress(date,,"a");
format date2 date9.;
date2=input(date,anydtdte11.);
week=intck(cats('week.',
weekday(mdy(1,1,year(input(date,anydtdte11.))))),
mdy(1,1,year(input(date,anydtdte11.))),
input(date,anydtdte11.))+1;
run;

HTH,
Art
Peter_C
Rhodochrosite | Level 12
Hi Kriti

That looks like code you have written, so just re-write it a little differently
"07JAN2010" is a character constant
"07JAN2010"d is a date constant
However, if your data "work.now_char" holds variable "date" as a character variable, your code will have to "interpret" it as a date to use relative tests like GT or LE..... not very different
First since you refer to "DATE" more than once, convert it to a sas date, just once like:
sas_date = input(DATE, date9.) ;

Your data step would adapt simply like:

> data combine;
> set now_char;
sas_date = input(DATE, date9.) ;

if sas_DATE LT "07JAN2010"d THEN

> Week = "Week1";

ELSE IF sas_DATE GT "07Jan08"d AND sas_DATE LT "15Jan08"d

> THEN
> Week = "Week2";
> RUN;

does that explain what you need?

peterC

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 850 views
  • 0 likes
  • 5 in conversation