BookmarkSubscribeRSS Feed
sasnewbie5
Fluorite | Level 6

Can someone help me adjust the below code so that values show for both the "salary" and "hdate" variables? 

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:mmddyy10 87-97;
	informat Hdate mmddyy10;
	
	if country = "US" then output US_trainees;
		else output AU_trainees;
		
		keep ID Lname Title Salary Hdate;
run;
4 REPLIES 4
sasnewbie5
Fluorite | Level 6

I adjusted the code so now it doesn't show blanks, but it lists the dates as 4 digit numbers with some being positive and others negative. Any advice?

ballardw
Super User

Your code did not use the informat if as posted:

informat Hdate mmddyy10;  there should be a period at the end of the informat:

 

informat Hdate mmddyy10. ;

 

The data likely was read properly but you have not given SAS any instruction to display the value as a date.

So add a format statement:

 

format Hdate mmddyy10. ;

again make sure that the format ends with a period.

Kurt_Bremser
Super User

Here a comprehensive example with data taken from your other thread:

data us australia;
input
  @1  id $6.
  @21 lname $18.
  @43 title $20.
  @64 salary dollar8.
  @73 country $2.
  @76 bdate mmddyy10.
  @87 hdate mmddyy10.
;
format
  salary dollar8.
  bdate hdate mmddyy10.
;
select (country);
  when ('AU') output australia;
  when ('US') output us;
  otherwise;
end;
cards;
120102 Tom          Zhou               M  Sales Manager        $108,255 AU 08/11/1969 06/01/1989
120103 Wilson       Dawes              M  Sales Manager         $87,975 AU 01/22/1949 01/01/1974
120121 Irenie       Elvish             F  Sales Rep. II         $26,600 AU 08/02/1944 01/01/1974
120261 Harry        Highpoint          M  Chief Sales Officer  $243,190 US 02/21/1969 08/01/1987
121018 Julienne     Magolan            F  Sales Rep. II         $27,560 US 01/03/1944 01/01/1974
121019 Scott        Desanctis          M  Sales Rep. IV         $31,320 US 06/25/1986 06/01/2004
;
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!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 737 views
  • 2 likes
  • 3 in conversation