BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
wang
Calcite | Level 5

here is my codes.it have some miskates,but i can not find them.please do me a favour. thank you very much.

data raw;

   input stckcd 1. @3 date yyyymm7.+1return 2.;

cards;

1 1995-01 1

1 1995-02 2

1 1995-03 3

1 1995-04 4

1 1995-05 5

1 1996-01 11

1 1996-02 22

1 1996-03 33

1 1996-04 44

2 1995-01 6

2 1995-02 7

2 1995-03 8

2 1995-04 9

2 1996-01 66

2 1996-02 77

2 1996-03 88

;

run;

data raw1;

set raw;

year=year(date);

month=month(date);

run;

proc print data=raw1;run;

here is the results

                         Obs    stckcd     date    return    year    month

                           1       1      11995       1      1992      11

                           2       1      21995       2      2020       3

                           3       1      31995       3      2047       8

                           4       1      41995       4      2074      12

                           5       1      51995       5      2102       5

                           6       1      11996      11      1992      11

                           7       1      21996      22      2020       3

                           8       1      31996      33      2047       8

                           9       1      41996      44      2074      12

                          10       2      11995       6      1992      11

                          11       2      21995       7      2020       3

                          12       2      31995       8      2047       8

                          13       2      41995       9      2074      12

                          14       2      11996      66      1992      11

                          15       2      21996      77      2020       3

                          16       2      31996      88      2047       8

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

data raw;

   input stckcd 1. @3 date $7.+1return 2.;

cards;

1 1995-01 1

1 1995-02 2

1 1995-03 3

1 1995-04 4

1 1995-05 5

1 1996-01 11

1 1996-02 22

1 1996-03 33

1 1996-04 44

2 1995-01 6

2 1995-02 7

2 1995-03 8

2 1995-04 9

2 1996-01 66

2 1996-02 77

2 1996-03 88

;

run;

data raw1;

set raw;

year=year(mdy(input(scan(date,2),2.),1,input(scan(date,1),4.)));

month=month(mdy(input(scan(date,2),2.),1,input(scan(date,1),4.)));

run;

proc print data=raw1;run;

             Obs    stckcd     date      return    year    month

                  1       1      1995-01       1      1995      1

                  2       1      1995-02       2      1995      2

                  3       1      1995-03       3      1995      3

                  4       1      1995-04       4      1995      4

                  5       1      1995-05       5      1995      5

                  6       1      1996-01      11      1996      1

                  7       1      1996-02      22      1996      2

                  8       1      1996-03      33      1996      3

                  9       1      1996-04      44      1996      4

                 10       2      1995-01       6      1995      1

                 11       2      1995-02       7      1995      2

                 12       2      1995-03       8      1995      3

                 13       2      1995-04       9      1995      4

                 14       2      1996-01      66      1996      1

                 15       2      1996-02      77      1996      2

                 16       2      1996-03      88      1996      3

View solution in original post

3 REPLIES 3
Linlin
Lapis Lazuli | Level 10

data raw;

   input stckcd 1. @3 date $7.+1return 2.;

cards;

1 1995-01 1

1 1995-02 2

1 1995-03 3

1 1995-04 4

1 1995-05 5

1 1996-01 11

1 1996-02 22

1 1996-03 33

1 1996-04 44

2 1995-01 6

2 1995-02 7

2 1995-03 8

2 1995-04 9

2 1996-01 66

2 1996-02 77

2 1996-03 88

;

run;

data raw1;

set raw;

year=year(mdy(input(scan(date,2),2.),1,input(scan(date,1),4.)));

month=month(mdy(input(scan(date,2),2.),1,input(scan(date,1),4.)));

run;

proc print data=raw1;run;

             Obs    stckcd     date      return    year    month

                  1       1      1995-01       1      1995      1

                  2       1      1995-02       2      1995      2

                  3       1      1995-03       3      1995      3

                  4       1      1995-04       4      1995      4

                  5       1      1995-05       5      1995      5

                  6       1      1996-01      11      1996      1

                  7       1      1996-02      22      1996      2

                  8       1      1996-03      33      1996      3

                  9       1      1996-04      44      1996      4

                 10       2      1995-01       6      1995      1

                 11       2      1995-02       7      1995      2

                 12       2      1995-03       8      1995      3

                 13       2      1995-04       9      1995      4

                 14       2      1996-01      66      1996      1

                 15       2      1996-02      77      1996      2

                 16       2      1996-03      88      1996      3

wang
Calcite | Level 5

thank you very much!!

i think i will have many problems in future, I look forward to your enthusiastic help。

Tom
Super User Tom
Super User

There is no YYYYMM informat. Try using ANYDTDTE instead.

data raw;

  informat date anydtdte. ;

  format date date9.;

  input stckcd date return ;

  year=year(date);

  month=month(date);

cards;

1 1995-01 1

1 1995-02 2

1 1995-03 3

1 1995-04 4

1 1995-05 5

1 1996-01 11

1 1996-02 22

1 1996-03 33

1 1996-04 44

2 1995-01 6

2 1995-02 7

2 1995-03 8

2 1995-04 9

2 1996-01 66

2 1996-02 77

2 1996-03 88

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
  • 3 replies
  • 603 views
  • 5 likes
  • 3 in conversation