Hi all, I'm learning SAS for my biological statistics class...
Anyway, I'm having problems with my output. In my dataset I have two words for one of my countries (United States) and when I go to output, it only puts United. Maybe I need to add a label? I'm using SAS 9.2.
data two;
length County $30;
input County life People physician Female Male;
label life = 'Life expectancy'
people = 'People per television'
physician = 'People per physician'
Female = 'Female life expectancy'
Male = 'Male Life expectancy';
datalines;
Argentina 70.5 4 370 74 67
Bangladesh 53.5 315 6166 53 54
Brazil 65 4 684 68 62
Canada 76.5 1.7 449 80 73
China 70 8 643 72 68
Colombia 71 5.6 1551 74 68
Egypt 60.5 15 616 61 60
Ethiopia 51.5 503 36660 53 50
France 78 2.6 403 82 74
Germany 76 2.6 346 79 73
India 57.5 44 2471 58 57
Indonesia 61 24 7427 63 59
Iran 64.5 23 2992 65 64
Italy 78.5 3.8 233 82 75
United States 75.5 1.3 404 79 7
run;
proc print data = two;
run; quit;
Easy solution if you make one change to your data. An ampersand after county (I presume that you meant that to be country) would allow your code to read a variable that contains a space. However, when you do that, the next variable has to be separated by at least two spaces. Thus, if you try the following, you will probably get the result that you are looking for.
data two;
length County $30;
input County & life People physician Female Male;
label life = 'Life expectancy'
people = 'People per television'
physician = 'People per physician'
Female = 'Female life expectancy'
Male = 'Male Life expectancy';
datalines;
Argentina 70.5 4 370 74 67
Bangladesh 53.5 315 6166 53 54
Brazil 65 4 684 68 62
Canada 76.5 1.7 449 80 73
China 70 8 643 72 68
Colombia 71 5.6 1551 74 68
Egypt 60.5 15 616 61 60
Ethiopia 51.5 503 36660 53 50
France 78 2.6 403 82 74
Germany 76 2.6 346 79 73
India 57.5 44 2471 58 57
Indonesia 61 24 7427 63 59
Iran 64.5 23 2992 65 64
Italy 78.5 3.8 233 82 75
United States 75.5 1.3 404 79 7
;
run;
proc print data = two;
run; quit;
Hi wakeborder556
If you are able to change your data, instead double-spacing data after country name, you might find it faster to place country names that contain a space, within quotes, like:
"United States" 75.5 1.3 404 79 7
and add (before the input statement) the new statement
infile datalines dsd dlm= " " ;
The feature that DSD provides for you here, is managing "columns" within quotes.
I reduced your step, only to clarify >>>
data two;
length County $30;
infile datalines dsd dlm= " " ;
input County life People physician Female Male;
datalines;
Argentina 70.5 4 370 74 67
"United States" 75.5 1.3 404 79 7
;
Conversely, as long as there are no numbers in County name and you don't have any missing data, here is another way that you could input the data without having to modify it:
data two;
length County $30;
input;
County=substr(_infile_,1,anydigit(_infile_)-2);
_infile_=substr(_infile_,anydigit(_infile_));
life=scan(_infile_,1," ");
People=scan(_infile_,2," ");
physician=scan(_infile_,3," ");
Female=scan(_infile_,4," ");
Male=scan(_infile_,5," ");
label life = 'Life expectancy'
people = 'People per television'
physician = 'People per physician'
Female = 'Female life expectancy'
Male = 'Male Life expectancy';
datalines;
Argentina 70.5 4 370 74 67
Bangladesh 53.5 315 6166 53 54
Brazil 65 4 684 68 62
Canada 76.5 1.7 449 80 73
China 70 8 643 72 68
Colombia 71 5.6 1551 74 68
Egypt 60.5 15 616 61 60
Ethiopia 51.5 503 36660 53 50
France 78 2.6 403 82 74
Germany 76 2.6 346 79 73
India 57.5 44 2471 58 57
Indonesia 61 24 7427 63 59
Iran 64.5 23 2992 65 64
Italy 78.5 3.8 233 82 75
United States 75.5 1.3 404 79 7
;
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.