BookmarkSubscribeRSS Feed
ashleighlentz
Calcite | Level 5

How do I create a variable "AGE" when using an external SAS data set via infile statement? The data set already has DOB in it.

This is how far I've gotten...

 

 

libname HW3 'c:\users\christopher\desktop\HW3';

data HW3.HW3_F18;

 

label       ID = "Subjects ID"

                  RACE = "Subjects Race"

                  DOB = "Subjects Date of Birth"

                  FEV = "Subjects Fev"

                  HEIGHT = "Subjects Height"

                  GENDER = "Subjects Gender"

                  WEIGHT = "Subjects Weight"

                  DURATION = "Subjects Duration"

                  WBCCOUNT = "Subjects WBCCount"

                  MARITAL = "Subjects Marital Status"

                  EDUCATION = "Subjects Education";

 

infile 'c:\users\christopher\desktop\HW3\hw3_f18.dat';

input ID Race $ DOB mmddyy10. FEV Height Gender $ Weight Duration WBCCOUNT Marital $ Education $20.;

run;

proc print data= HW3.HW3_F18;

run;

4 REPLIES 4
Reeza
Super User

How do I create a variable "AGE" when using an external SAS data set via infile statement? The data set already has DOB in it.

 

It's not any different than if you were doing it with a SAS data set, is there some specific reason you think there is?

You can add the computation after the INPUT statement. 

 

 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

age=int((today()-dob)/365.25);
age=intck('year',dob,today() "continuous" );
 
added the fourth argument to intck as @PGStats noted .
 
PGStats
Opal | Level 21

Let's not forget the fourth argument when calling intck to get the right result

 

age = intck('year', dob, today(), "CONTINUOUS");

PG
Kurt_Bremser
Super User

"external SAS data set" is an oxymoron.

It's either a SAS dataset, which is considered (in SAS speak) "internal", or an external file, which is not a SAS dataset. It is data, but it is not a dataset.

"SAS dataset" denotes a file with the extension .sas7bdat (in earlier days .ssd01 or .sd1) which resides in a directory for which you have a libname assigned.

 

Since, in your case, the library points to the same location where the external file resides, then after the data step you will have two files in c:\users\christopher\desktop\HW3:

  • hw3_f18.dat
  • hw3_f18.sas7bdat

the first is the external file, the second is the SAS dataset.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 931 views
  • 2 likes
  • 5 in conversation