BookmarkSubscribeRSS Feed
michelle05
Fluorite | Level 6

Here's my code! When I run the code, I'm not getting any errors or results.  I'm not sure what I did wrong.  The question says to create a new sas data set called AGES that contains all the variables in ABC_CORP plus three new variables.  One is AGE_ACTUAL, which is the exact age from DOB to January 15, 2005.  The second is AGE_TODAY, which is the age as of the date the program is run, rounded to the nearest tenth of the year.  The third is AGE, with the fractional part dropped, as of the date stored in the variable VISIT_DATE.  

***Program to create data set ABC_CORP;
DATA ABC_CORP;
DO SUBJ = 1 TO 10;
DOB = INT(RANUNI(1234)*15000);
VISIT_DATE = INT(RANUNI(0)*1000) + '01JAN2000'D;
OUTPUT;
END;
FORMAT DOB VISIT_DATA DATE9.;
RUN;
***program to create data set AGES;
DATA AGES;
AGE_ACTUAL=YRDIF(DOB,'15JAN2005'D,'ACTUAL');
AGE_TODAY= ROUND(YRDIF(DOB,TODAY(),'ACTUAL'),.1);
AGE= INT(AGE);
VISIT_DATE= INT(RANUNI(0)*1000)+ '01JAN2000'D;
RUN;

 

7 REPLIES 7
VinitvictorCorr
Quartz | Level 8

Heres your below program with the required updates :-

 

 

DATA ABC_CORP;
FORMAT DOB VISIT_DATE DATE9.;
DO SUBJ = 1 TO 10;
DOB = INT(RANUNI(1234)*15000);
VISIT_DATE = INT(RANUNI(0)*1000) + '01JAN2000'D;
OUTPUT;
END;
RUN;
***program to create data set AGES;
DATA AGES;
set abc_corp;
AGE_ACTUAL=YRDIF(DOB,'15JAN2005'D,'ACTUAL');
AGE_TODAY= ROUND(YRDIF(DOB,TODAY(),'ACTUAL'),.1);
AGE= INT(AGE_TODAY);
VISIT_DATE= INT(RANUNI(0)*1000)+ '01JAN2000'D;
RUN;

 

 

You did not set the abc-corp data set and hence you were not getting the results. Also the age= statement had age which was niot initialised, hence i assumed and put age_today instead of age Please check if this is what you want, otherwise please let me know .

michelle05
Fluorite | Level 6

Thank you!  It still didn't give results but I see where I went wrong (I think).  I'm going to redo the code and add some more codes to see if that would work.  Thank you for taking out the time to answer back.  I'm new to SAS and I usually have 8 problems a chapter but get stuck on some that I just need a little guidance and help with.  Thank you again!

VinitvictorCorr
Quartz | Level 8
sure. just post a question in sas communitiies if you need anything
VinitvictorCorr
Quartz | Level 8
and it should give result.. i tried the code before posting it
ballardw
Super User

@michelle05 wrote:

Thank you!  It still didn't give results but I see where I went wrong (I think).  I'm going to redo the code and add some more codes to see if that would work.  Thank you for taking out the time to answer back.  I'm new to SAS and I usually have 8 problems a chapter but get stuck on some that I just need a little guidance and help with.  Thank you again!


 

Providing the LOG from running code is often very informative. That is why SAS provides the LOG.

So post the code and any messages from the log. Copy and paste into a code box opened using the forum's {I} or "running man" icon.

 

Example:

161  proc print data=sashelp.class;
162     where sex='Female';
163  run;

NOTE: No observations were selected from data set SASHELP.CLASS.
NOTE: There were 0 observations read from the data set SASHELP.CLASS.
      WHERE 0 /* an obviously FALSE WHERE clause */ ;
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds

The "No observations" and the "FALSE WHERE clause" might remind me in this case the value in the data set for SEX is "F" not "Female". So little things in the log are actually helpful and the actual coded is needed to point towards likely changes needed.

michelle05
Fluorite | Level 6

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

70        

71         ***Program to create new data set called AGES;

72         data AGES;

73         SET ABC_CORP;

74         AGE_ACTUAL= YRDIF(DOB,'01JAN2015'd,'ACTUAL');

75         AGE_TODAY=ROUND(YRDIF(DOB,TODAY(),'ACTUAL'),.1);

76         AGE= INT(YRDIF(DOB,'01JAN2015'd,'ACTUAL'));

77         VISIT_DATE= INT(AGE);

78         FORMAT DOB VISIT_DATE DATE9.;

79         RUN;

NOTE: There were 10 observations read from the data set WORK.ABC_CORP.

NOTE: The data set WORK.AGES has 10 observations and 6 variables.

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      user cpu time       0.00 seconds

      system cpu time     0.00 seconds

      memory              976.90k

      OS Memory           29100.00k

      Timestamp           09/27/2019 12:52:24 AM

      Step Count                        180 Switch Count 2

      Page Faults                       0

      Page Reclaims                     181

      Page Swaps                        0

      Voluntary Context Switches        9

      Involuntary Context Switches      0

      Block Input Operations            0

      Block Output Operations           264

     

80        

81         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

92        

 

michelle05
Fluorite | Level 6

After meditating and reworking the code, I now see why I didn't have any results.  I didn't put PROC PRINT.  As soon as I entered that, the code printed.  

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 811 views
  • 0 likes
  • 3 in conversation