BookmarkSubscribeRSS Feed
sasnewbie5
Fluorite | Level 6

Screen Shot 2018-12-11 at 4.26.14 PM.png

I have a .txt file that I need to use to create two data sets with one data step: one dataset contains people from the US and the other contains people from AU - the country variable should not be kept in the output datasets.

*Only people with the title sales rep are to be included.

*Each dataset should only contain the fields with arrows by them.

 

The code I have below has many notes in the log and doesn't list dates (I tried formatting), and I'm not sure how I'd separate it into two datasets based on country. Any help is welcomed and appreciated! 

filename sales1 "/folders/myfolders/hw9/sales1.txt";
data US_trainees;
	infile sales1;
	input ID 1-6 LName $ 21-39 
		  Title $ 43-63 Salary 64-72 Country $ 73-75 
		  Hdate 87-97;
	format Bdate mmddyy10;	  
run;	

 

4 REPLIES 4
SuryaKiran
Meteorite | Level 14

Looks like a homework problem. Here are some tips:

 

- Informat: You need to tell SAS how to read the value using informat. In this case you didn't mention the informat for the date values which resulted in missing values and notes in the log.

- You can create multiple datasets in single data step. You need to tell which record goes into which table.

data male Female;
set sashelp.class;
if sex='M' then output male;
else output Female;
run;

data male(where=(sex='M')) Female(where=(sex='F'));
set sashelp.class;
run;

- You can use INDEX() or FIND() function to look for Sales Reps in the fields and filter for those. 

- Use KEEP or DROP for your required variables in output.

Thanks,
Suryakiran
sasnewbie5
Fluorite | Level 6

Screen Shot 2018-12-11 at 4.26.14 PM.png

I have a .txt file that I need to use to create two data sets with one data step: one dataset contains people from the US and the other contains people from AU - the country variable should not be kept in the output datasets.

*Only people with the title sales rep are to be included.

*Each dataset should only contain the fields with arrows by them.

 

The code I have below has many notes in the log and doesn't list dates (I tried formatting), and I'm not sure how I'd separate it into two datasets based on country. Any help is welcomed and appreciated! 

 

filename sales1 "/folders/myfolders/sascode/sales1.txt";
data US_trainees;
infile sales1;
input ID 1-6 LName $ 21-39
Title $ 43-63 Salary 64-72 Country $ 73-75
Hdate 87-97;
format Bdate mmddyy10;
run;
ballardw
Super User

I don't see any instruction telling SAS to read your date variables as if they are dates in the mmddyy10 format in the source file.

INFORMAT is used to specify that. You FORMAT BDATE but READ HDATE. One of these things is not like the other.

 

The generic approach to reading into each multiple sets is the DATA statement must list the names of all of the sets wanted.

Then a separate explicit output statement addressing the desired data set is used:

 

data set1

        set2

;

<other code>

    if variable = value then output set1;

    else output set2;

run;

if you need /want more than one data set list it. To send records to a specific set though you still need an output statement and the simple if/then/else likely won't quite work as desired for 3 or more sets.

 

You can keep the variables wanted with a KEEP statement, Remove the ones you don't want with a DROP statement.

 

I believe we may have mentioned that posting the log, or if many repeated warning or errors, some of the log in a code box.

sasnewbie5
Fluorite | Level 6

Thank you @ballardw. I'm not familiar with the informat function. Could you help me with applying that to the below code?

filename sales1 "/folders/myfolders/sascode/sales1.txt";
data US_trainees AU_trainees;
	infile sales1;
	input ID 1-6 LName $ 21-39 
		  Title $ 43-63 Salary 64-72 Country $ 73-75 
		  Hdate 87-97;
	format Hdate mmddyy10;
	
	if country = "US" then output US_trainees;
		else output AU_trainees;
		
		keep ID Lname Title Salary Hdate;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 4 replies
  • 966 views
  • 0 likes
  • 3 in conversation