This is not addressed to your question, but the code
age = yrdif(dob1,'01jan2023'd)/365;
doesn't make sense. Since the YRDIF function calculates the number of years between dob1 and jan 1, 2023, there is no reason to divide that result by 365. What the code above produces is "number of 365-year intervals" between the dates.
It's true that you can tell yrdif what year-calibration (to support various conventions in finance) you want to use, and perhaps that's what you wanted to do (see discussion of the basis argument in YRDIF Function). But if you use this argument, then it must be the 3rd entry inside the parentheses, not outside the parentheses. And as a character argument, it will have to be in quotes. In your case, the likely basis would be "age", as in
age = yrdif(dob1,'01jan2023'd,'age');
And even that is unnecessary, since 'age' is the default basis.
Define variables using a by statement on SAS OnDemand for academics
If this is supposed to be an instruction from some sort of teacher I would find another class. The only variables "defined" with a BY statement are some automatic variables SAS creates in a data step to indicate if a particular observation is the the first or last of a given variable for a combination of variables on a BY statement. I might accept something like "Create variables to use later on a BY statement" but not as phrased.
What the BY statement does is attempt to do the same operations for each level of a given by variable or combination. Typically that requires sorting the data into that order using Proc Sort.
Consider the SASHELP.CLASS data set that you should have available as an example. Suppose that we want to get summary statistics for the student weight and height variable By sex.
Proc sort data=sashelp.class out=work.class; by sex; run; proc means data=work.class n mean min max std; by sex; var height weight; run;
This creates a summary for Sex=F and another for Sex=M. This what BY does, process groups of observations.
libname patients '/home/u63367626/PATIENTS'; data patients.patt1; set patt2; format dob1 date9.; *removes spaces and adds / between values. Easier to use the MDY function; dob=compress(cat(month,'/',day,'/',year)); dob1=input(dob,mmddyy10.); *incorrect calculation of age, should be age = yrdif(dob1, '01jan2023'd, dob1); age = yrdif(dob1,'01jan2023'd)/365; *ends current data step; run; *outside of data step - does nothing/error; output; *outside of data step - does nothing/error; =2; *outside of data step - does nothing/error; output; *outside of data step - does nothing/error; run; /*evaluating the statistical parameters for age*/ proc sort data=patients.patt1; *outside of data step - does nothing/error; by ; run; proc means data=patients.patt1; variables age; *usually see var age not the full word variables; output out= agestsatz; by ; *no variable specified to break up the analysis; run;
See comments on your code.
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.
For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.
Find more tutorials on the SAS Users YouTube channel.