BookmarkSubscribeRSS Feed
ishaqwright21o
Calcite | Level 5

I am trying to designate character variables to specific date intervals yet it only produces numerical and does not read quoted statements. I did create a new date variable and was going to do the designations. Please help. Thanks

 

Data work.date_of_Death;

set work.eclrsvs_fludata_new_NoDupkey;

death_date=input(Dt_Of_death,yymmdd10.);

format death_date mmddyy10.;

if Death_date le 08/01/2020 then Week_No = "2031";

Else if Death_date le 08/08/2020 then Week_No = "2032";

Else if Death_date le 08/15/2020 then Week_No = "2033";

Else if Death_date le 08/22/2020 then Week_No = "2034";

Else if Death_date le 08/29/2020 then Week_No = "2035";

run;

 

 

2 REPLIES 2
Tom
Super User Tom
Super User

I am not sure what you are asking about.

The code you posted appears to be creating two variables, but if either one already exists in eclrsvs_fludata_new_NoDupkey then their type (and storage length) has already been defined and cannot be changed.

 

If you want to explicit about how death_date or Week_No  is defined then define them before using them in your assignment statements.

 

Also why are you comparing date values (which are integers) to the results of those division expressions in your IF conditions?

If you want to compare a date value to a specific date you can use a date literal instead.   Date literals are quoted strings that can be converted to a date by the DATE informat followed by the letter D.

 

data work.date_of_Death;
  set work.eclrsvs_fludata_new_NoDupkey;
  length death_date 8 Week_No $4 ;
  death_date=input(Dt_Of_death,yymmdd10.);
  format death_date mmddyy10.;
  if Death_date le '01AUG2020'd then Week_No = "2031";
  else if Death_date le '08AUG2020'd then Week_No = "2032";
  slse if Death_date le '15AUG2020'd then Week_No = "2033";
  else if Death_date le '22AUG2020'd then Week_No = "2034";
  else if Death_date le '29AUG2020'd then Week_No = "2035";
run;

 

Patrick
Opal | Level 21

Here another option for calculating week_no:

data work.eclrsvs_fludata_new_NoDupkey;
  do _dt='01aug2020'd, '02aug2020'd,'01Jul2020'd to '20Sep2020'd by 5;
    Dt_Of_death=put(_dt,yymmdd10.);
    output;
  end;
  drop _dt;
  stop;
run;

data work.date_of_Death;
  set work.eclrsvs_fludata_new_NoDupkey;
  length death_date 8 Week_No $4;
  death_date=input(Dt_Of_death,yymmdd10.);

  format death_date mmddyy10.;
  retain _base_dt;
  format _base_dt date9.;
  if _n_=1 then _base_dt=intnx('week','01AUG2020'd,-2031,'b');
  week_no=put(intck('week',_base_dt,death_date), z4.);
/*  drop _base_dt;*/
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 673 views
  • 0 likes
  • 3 in conversation