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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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