BookmarkSubscribeRSS Feed
wakeborder556
Calcite | Level 5

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;

3 REPLIES 3
art297
Opal | Level 21

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;

Peter_C
Rhodochrosite | Level 12

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

;

art297
Opal | Level 21

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

;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 3 replies
  • 685 views
  • 1 like
  • 3 in conversation