Quantcast
Channel: Statistics Help @ Talk Stats Forum - SAS
Viewing all articles
Browse latest Browse all 310

Reading in variables with spaces

$
0
0
A co-worker is going through the SAS learning module and came across something I have not been able to figure out how to read in the data 100% correct :(.

Here is the data SAS gave him:

data test;
input emp_id
f_name $
l_name $
gender $
salary
job_title $
country $
birth_date
hire_date;
cards;
120102 Tom Zhou M 108255 Sales Manager AU 3510 10744
120103 Wilson Dawes M 87975 Sales Manager AU -3996 5114
120121 Irenie Elvish F 26600 Sales Rep. II AU -5630 5114
120122 Christina Ngan F 27475 Sales Rep. II AU -1984 6756
120123 Kimiko Hotstone F 26190 Sales Rep. I AU 1732 9405
120124 Lucian Daymond M 26480 Sales Rep. I AU -233 6999
120125 Fong Hofmeister M 32040 Sales Rep. IV AU -1852 6999
120126 Satyakam Denny M 26780 Sales Rep. II AU 10490 17014
120127 Sharryn Clarkson F 28100 Sales Rep. II AU 6943 14184
120128 Monica Kletschkus F 30890 Sales Rep. IV AU 9691 17106
120129 Alvin Roebuck M 30070 Sales Rep. III AU 1787 9405
120130 Kevin Lyon M 26955 Sales Rep. I AU 9114 16922
run;

The problem is that the job title (in bold) has spaces. I know there is a way to tell SAS to skip to the next variable when 2 spaces are found, but let's say there were 10,000 rows and that would be too tedious. I also know I could just simply add a space between some of the job titles and country names but again, let's say I had 10,000 rows and didn't want to do this.

I've also tried messing around with : and & but with no luck.

I found something that ALMOST worked:

job_title $13. +1 -> placing that in the input line

However, if you try it, there are a few rows for which the country only outputs U instead of AU (when the length of job title is 12 or less). If I try job_title $12. +2 it also almost works but not quite.

Any suggestions on how to read this data in properly without actually changing or modifying the data (such as adding spaces)?

Viewing all articles
Browse latest Browse all 310

Trending Articles