BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kurt_Bremser
Super User

That is (as already mentioned) because variable month is already defined as character.

As also already mentioned, replace all your occurences of month with dcmonth to use the newly created variable.

byeh2017
Quartz | Level 8

sample.png

 

Thanks. Ok changed everything to dcdeathdate from month. I'm still getting this weird error:

 

data cdc.monthanalysis;
set cdc.originaldatasetdupidclean;
  dcmonth = intnx('dcdeathdate',datepart(DCDeathDate),0,'begin'); /* normalizes to a month */
  format dcdeathdate yymon7.;
run;
byeh2017
Quartz | Level 8

Got it to work. I had to leave the intnx('month'... alone. Thanks for your help!

 

data cdc.monthanalysis;
set cdc.originaldatasetdupidclean;
  dcmonth = intnx('month',datepart(DCDeathDate),0,'begin'); /* normalizes to a month */
  format dcmonth yymon7.;
run;
ballardw
Super User

One of the big strengths of date, time and datetime values is the ability to change the display values without having to always add variables by using a custom format.

For your consideration:

data work.SAMPLEMONTHANALYSIS;
  infile datalines dsd truncover;
  input DCDeathDate:DATETIME16. HepCscreeningdone:$3. HCVresult:$8. _OrganizationTax:$9.;
datalines4;
28NOV16:00:00:00,No,,404908043
12DEC16:00:00:00,Yes,Negative,202193544
30NOV16:00:00:00,Yes,Negative,202453987
23DEC16:00:00:00,No,,202051689
06NOV16:00:00:00,Yes,Positive,211328703
18DEC16:00:00:00,No,,204871594
23NOV16:00:00:00,No,,211328703
22NOV16:00:00:00,No,,202051689
26DEC16:00:00:00,Yes,Negative,404879663
18NOV16:00:00:00,No,,402022253
09DEC16:00:00:00,Yes,Negative,204871781
30NOV16:00:00:00,No,,400153061
17NOV16:00:00:00,Yes,Negative,206120730
27DEC16:00:00:00,Yes,Negative,200010674
28DEC16:00:00:00,Yes,Negative,245428880
04NOV16:00:00:00,Yes,Negative,212806766
10DEC16:00:00:00,Yes,Negative,200010674
04NOV16:00:00:00,No,,404945164
20DEC16:00:00:00,No,,211328703
27DEC16:00:00:00,Yes,Negative,202050840
05DEC16:00:00:00,Yes,Negative,202051876
04NOV16:00:00:00,No,,202051689
16DEC16:00:00:00,Yes,Negative,404981622
19NOV16:00:00:00,Yes,Negative,206063383
10NOV16:00:00:00,No,,211385767
26NOV16:00:00:00,Yes,Negative,200010674
04NOV16:00:00:00,No,,204871594
25DEC16:00:00:00,No,,205165453
18NOV16:00:00:00,Yes,Negative,205005527
25NOV16:00:00:00,Yes,Negative,205005527
31DEC16:00:00:00,Yes,Negative,404866659
01NOV16:00:00:00,No,,211328703
21NOV16:00:00:00,No,,416289947
02NOV16:00:00:00,No,,401945605
02DEC16:00:00:00,No,,202051689
05DEC16:00:00:00,No,Negative,404905821
26DEC16:00:00:00,Yes,Negative,200010674
05NOV16:00:00:00,No,,400115362
15DEC16:00:00:00,Yes,Negative,211385767
02DEC16:00:00:00,Yes,Negative,405001466
14DEC16:00:00:00,Yes,Negative,202051876
04DEC16:00:00:00,Yes,Negative,400153061
10DEC16:00:00:00,Yes,Negative,200010674
28DEC16:00:00:00,Yes,Negative,404866659
30NOV16:00:00:00,No,,400153061
10DEC16:00:00:00,No,Negative,404945217
29NOV16:00:00:00,Yes,Negative,405018831
11DEC16:00:00:00,Yes,Negative,404907730
07NOV16:00:00:00,,,404514762
02DEC16:00:00:00,No,,406131939
18DEC16:00:00:00,No,,202051689
06NOV16:00:00:00,No,,211385767
08DEC16:00:00:00,Yes,Negative,404866123
21DEC16:00:00:00,Yes,Negative,404866659
04NOV16:00:00:00,No,,400153061
04NOV16:00:00:00,Yes,Negative,405032806
29DEC16:00:00:00,Yes,Negative,204927543
21DEC16:00:00:00,Yes,Positive,212153756
05NOV16:00:00:00,Yes,Negative,200199702
30DEC16:00:00:00,No,Negative,404905821
10NOV16:00:00:00,Yes,Negative,205210467
14NOV16:00:00:00,No,,211385767
14NOV16:00:00:00,Yes,Negative,200010674
26NOV16:00:00:00,No,,202051876
22DEC16:00:00:00,Yes,Negative,406055879
21DEC16:00:00:00,Yes,Negative,204927543
18NOV16:00:00:00,No,Negative,200007143
11DEC16:00:00:00,Yes,Negative,405018831
10NOV16:00:00:00,No,,211328703
28NOV16:00:00:00,No,Negative,404945217
07DEC16:00:00:00,Yes,Negative,205284093
17NOV16:00:00:00,No,,202051876
04DEC16:00:00:00,Yes,Negative,202051876
16DEC16:00:00:00,No,,202051689
14NOV16:00:00:00,No,,202051689
14NOV16:00:00:00,Yes,Negative,202453987
13NOV16:00:00:00,No,Negative,218071681
21NOV16:00:00:00,No,,202193544
02DEC16:00:00:00,No,,404945164
03DEC16:00:00:00,No,,211328703
13NOV16:00:00:00,Yes,Negative,404865981
17NOV16:00:00:00,No,Negative,200007143
17NOV16:00:00:00,No,,202051689
06DEC16:00:00:00,Yes,Negative,205250618
03DEC16:00:00:00,Yes,Positive,202051689
14NOV16:00:00:00,Yes,Negative,404865981
25NOV16:00:00:00,No,,202193544
22NOV16:00:00:00,Yes,Negative,205250618
15DEC16:00:00:00,Yes,Negative,218064699
05NOV16:00:00:00,Yes,Positive,201990694
02DEC16:00:00:00,Yes,Negative,211385767
30NOV16:00:00:00,Yes,Negative,406055879
21DEC16:00:00:00,No,Negative,417876711
02NOV16:00:00:00,Yes,Negative,404866659
08NOV16:00:00:00,No,,202907970
05DEC16:00:00:00,No,,202249968
08DEC16:00:00:00,Yes,Negative,404879663
30NOV16:00:00:00,No,,205284093
28NOV16:00:00:00,No,,404879663
03NOV16:00:00:00,Yes,Negative,205250618
09NOV16:00:00:00,Yes,Negative,200010674
26DEC16:00:00:00,Yes,Negative,202453987
17DEC16:00:00:00,No,,202051689
09DEC16:00:00:00,Yes,Negative,204931949
05NOV16:00:00:00,No,,211385767
18NOV16:00:00:00,No,,211327161
30DEC16:00:00:00,Yes,Negative,200209103
09NOV16:00:00:00,Yes,Negative,202193544
23DEC16:00:00:00,Yes,Positive,404865981
15DEC16:00:00:00,Yes,Positive,211328703
09DEC16:00:00:00,Yes,Negative,203827608
27NOV16:00:00:00,No,,202051876
26NOV16:00:00:00,No,,202051876
15NOV16:00:00:00,No,,202051876
23NOV16:00:00:00,Yes,Negative,206047464
19NOV16:00:00:00,Yes,Negative,202193544
26DEC16:00:00:00,Yes,Positive,212153756
30DEC16:00:00:00,No,,209446900
19NOV16:00:00:00,No,,400153061
12DEC16:00:00:00,Yes,Negative,212002580
17NOV16:00:00:00,No,,202051689
31DEC16:00:00:00,Yes,Negative,200010674
26DEC16:00:00:00,Yes,Negative,202442981
01NOV16:00:00:00,Yes,Negative,200010674
30NOV16:00:00:00,No,,204871594
21NOV16:00:00:00,Yes,Negative,402006592
25DEC16:00:00:00,Yes,Negative,404865981
03NOV16:00:00:00,No,,202051876
29NOV16:00:00:00,Yes,Negative,200010674
09DEC16:00:00:00,Yes,Negative,404866123
25DEC16:00:00:00,Yes,Negative,402006592
31DEC16:00:00:00,Yes,Negative,404866659
06DEC16:00:00:00,Yes,Negative,404941827
14NOV16:00:00:00,Yes,Negative,211328703
22DEC16:00:00:00,Yes,Negative,202050840
17NOV16:00:00:00,Yes,Negative,200010674
29NOV16:00:00:00,Yes,Negative,204923707
12NOV16:00:00:00,Yes,Negative,404907730
25NOV16:00:00:00,No,,202051876
23DEC16:00:00:00,Yes,Negative,202051876
11DEC16:00:00:00,Yes,Negative,202193544
27DEC16:00:00:00,Yes,Negative,202948819
17NOV16:00:00:00,No,,404907730
15NOV16:00:00:00,No,,202051876
14DEC16:00:00:00,Yes,Negative,211385767
12NOV16:00:00:00,Yes,Negative,206063383
07NOV16:00:00:00,No,,205284093
03DEC16:00:00:00,Yes,Negative,406160755
06DEC16:00:00:00,No,,209446900
14DEC16:00:00:00,No,,202051689
21NOV16:00:00:00,No,,400153061
11DEC16:00:00:00,Yes,Negative,402006592
03DEC16:00:00:00,Yes,Negative,404941827
16DEC16:00:00:00,No,,209446900
10NOV16:00:00:00,Yes,Negative,404866659
17DEC16:00:00:00,Yes,Positive,202193544
25DEC16:00:00:00,Yes,Negative,211385767
09DEC16:00:00:00,Yes,Negative,204955076
14NOV16:00:00:00,No,,202249968
14DEC16:00:00:00,Yes,Negative,401945605
30NOV16:00:00:00,No,,202193544
16NOV16:00:00:00,No,,202051689
21NOV16:00:00:00,No,,202051689
18NOV16:00:00:00,Yes,Negative,404866123
04NOV16:00:00:00,Yes,Negative,201990694
30NOV16:00:00:00,Yes,Positive,402022253
20NOV16:00:00:00,No,,400153061
02DEC16:00:00:00,Yes,Negative,202463752
20DEC16:00:00:00,No,,202051689
08DEC16:00:00:00,Yes,Negative,202193544
01DEC16:00:00:00,No,,202051689
02DEC16:00:00:00,Yes,Positive,212002580
04DEC16:00:00:00,No,,202051689
10NOV16:00:00:00,No,,202051689
28NOV16:00:00:00,Yes,Negative,200010674
01DEC16:00:00:00,Yes,Negative,205218030
09NOV16:00:00:00,No,,204871594
04DEC16:00:00:00,Yes,Negative,402022253
15NOV16:00:00:00,Yes,Negative,200010674
23NOV16:00:00:00,Yes,Negative,400037875
03NOV16:00:00:00,No,,202249968
10NOV16:00:00:00,No,Negative,404905821
14NOV16:00:00:00,No,Negative,405001466
08DEC16:00:00:00,Yes,Negative,202051876
08DEC16:00:00:00,Yes,Positive,400153061
21DEC16:00:00:00,Yes,Negative,202193544
27NOV16:00:00:00,No,,404879663
18NOV16:00:00:00,No,,202051876
30DEC16:00:00:00,Yes,Negative,202051876
22DEC16:00:00:00,No,,202051689
05DEC16:00:00:00,Yes,Negative,205005527
22NOV16:00:00:00,No,,202051689
29NOV16:00:00:00,Yes,Negative,212153756
09DEC16:00:00:00,No,,206089169
21DEC16:00:00:00,Yes,Negative,202193544
11NOV16:00:00:00,Yes,Negative,404907730
28DEC16:00:00:00,No,,209446900
19DEC16:00:00:00,Yes,Negative,211385767
20DEC16:00:00:00,No,,202051689
07DEC16:00:00:00,Yes,Negative,404866123
;;;;
run;

proc format library=work;
/* default datetime18 shows 2 digit year (with 2 leading blanks, this makes custom
   datetime format that uses 18 digits and 4 digit year*/
picture mydatetime ( default=15)
low-high = '%B %Y'   (datatype=datetime)
;
run;

proc tabulate data=work.SAMPLEMONTHANALYSIS;
   class _OrganizationTax;
   class DCDeathDate;
   format DCDeathDate Mydatetime.;
   class HepCscreeningdone HCVresult;
   table _OrganizationTax="Organization" * DCDeathDate="",
        HepCscreeningdone='HCV Screening',
        HCVresult="HCV Status"*n=""
        /
   ;
run;

Note that with Proc tabulate you could define formats for the screening and result variables and use the Preloadfmt to display all the possible screening and result values to keep the tables more consistent.

 

 

PLEASE do not include your library names in example data.

GPNaveen
Fluorite | Level 6

Hello,

 

I tried using Proc tabulate for the same after creating a variable to capture Month value.
The code is as below for the proc tabulate. Please run this code and check if this serves the purpose.

 

Example:

 

Proc Tabulate data=have;
class _OrganizationTax month HepCscreeningdone HCVresult / missing;
table _OrganizationTax='Organistaion' , HepCscreeningdone='HCV Screening' , month =' ' * HCVresult='HCV status' ;
KEYLABEL N=' ';
run;

 

Thanks
GP

byeh2017
Quartz | Level 8

Thank you. I used that following code and got something like this:

 

sample.png

 

proc format library=mydata;
/* default datetime18 shows 2 digit year (with 2 leading blanks, this makes custom
   datetime format that uses 18 digits and 4 digit year*/
picture mydatetime ( default=15)
low-high = '%B %Y'   (datatype=datetime)
;
run;

Proc Tabulate data=mydata.originaldatasetdupidclean;
class _Organizationtax dcdeathdate HepCscreeningdone HCVresult / missing;
table _Organizationtax='Organistaion' , HepCscreeningdone='HCV Screening' , dcdeathdate ='Month' * HCVresult='HCV status' ;
KEYLABEL N=' ';
run;
byeh2017
Quartz | Level 8

Also, what exactly is keylabel N in that code?

 

proc format library=cdc;
/* default datetime18 shows 2 digit year (with 2 leading blanks, this makes custom
   datetime format that uses 18 digits and 4 digit year*/
picture mydatetime ( default=15)
low-high = '%B %Y'   (datatype=datetime)
;
run;

Proc Tabulate data=cdc.originaldatasetdupidclean;
class _Organizationtax dcdeathdate HepCscreeningdone HCVresult / missing;
table _Organizationtax='Organistaion' , HepCscreeningdone='HCV Screening' , dcdeathdate ='Month' * HCVresult='HCV status' ;
KEYLABEL N=' ';
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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
  • 22 replies
  • 1310 views
  • 1 like
  • 4 in conversation