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;
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?
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.
Please post a few example lines from your external file, so we have something to test code against.
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;
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.