So I have a .sas7bdat file. I have successfully opened it by using lib name and
data new ;
set roster.employee_roster ;
run;
However I am asked to print a table with only peoples last names that start with Z or Y. Im having trouble figuring this out since the names are stored as full names in one column. any suggestions?
If the assignment is to only print records with first names starting with Z or X, it shouldn't matter if the name is stored as a full name?
Simply do something like this
proc print data=sashelp.class;
where substr(name, 1, 1)="A";
run;
Sorry I rushed to type it. Its asking for LASTNAMES that start with Z or Y. But I only have the column of FULLNAMES
Do i put these steps in the data step or the proc step? sorry I'm very new to this
data work.a;
name="Joe Zions";
output;
name="Joe Smith";
output;
name="Joe Yuck";
output;
run;
data work.b;
set work.a;
where substr(upcase(scan(name,2," ")),1,1) in ('Z','Y');
run;
This is for one column of data. What if I'm working with multiple columns such as a .sas7bdat file?
file name: employee_roster.sas7bdat
@jovane0700 wrote:
This is for one column of data. What if I'm working with multiple columns such as a .sas7bdat file?
file name: employee_roster.sas7bdat
The technique @mdavidson shows is intended to subset a data set on the values as specified (under some assumptions you have not addressed such as order of first and last name in the name field and some other obnoxious name related stuff). You would use your data set in the place of the work.a on the set statement in the second data step in the example and the work.b set is the one you would print from. His work.a data set is shown to have something concrete to demonstrate one approach. If your name field looks different than shown in work.a then you need to provide examples.
Here's a good starting point It assumes (as you originally stated) that the full name is stored in a single variable:
proc print data=roster.employee_roster;
where scan(full_name, -1) in : ("Y", "Z");
run;
For this to work, you absolutely must not remove the colon after IN.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.