BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Steelers_In_DC
Barite | Level 11

Hello, I am trying to get the hang of arrays and having trouble.  The below code is intended to take current weight and get a goal weight.  Instead of doing that I am adding two variables and not calculating goal weight.  If anyone can see the errors and advise I would appreciate it.  Thanks:

data start;

infile datalines;

input name $ sex $ weight1 weight2;

cards;

sara f 120 119

bill m 220 219

;

run;

data end (drop=i);

set start;

  array start_array{*} _numeric_;

  array end_array{*} goal_weight1-goal_weight2;

  if sex=f then do

  i=1 to 2;

  end_array{i}=start_array{i}*.95;

  end;

  else if sex=m then do

  i=1 to 2;

  end_array{i}=start_array{i}*.9;

  end;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  In answer to your more general question about arrays, I have always found this to be a good paper.

http://support.sas.com/rnd/papers/sgf07/arrays1780.pdf

  But, as you learned, the problem was not so much with array processing as IF statement syntax and the need for quoting character strings in comparisons.

cynthia

View solution in original post

4 REPLIES 4
Haikuo
Onyx | Level 15

Not sure if you have other issues with the code, but is it supposed to be like:

if sex='f' then do

else if sex='m' then do

Haikuo

PGStats
Opal | Level 21

The only prroblem I see is the absence of quotes around f and m in your if statements. PG

PG
Tom
Super User Tom
Super User

Other than the missing quotes around the string literals and the strange indentation the program looks fine.

It is converting the existing weights to goal weights by multiplying by a fraction that depends on gender.

What did you want to do differently?

                                             goal_      goal_

Obs    name    sex    weight1    weight2    weight1    weight2

1     sara     f       120        119        114       113.05

2     bill     m       220        219        198       197.10

Cynthia_sas
SAS Super FREQ

Hi:

  In answer to your more general question about arrays, I have always found this to be a good paper.

http://support.sas.com/rnd/papers/sgf07/arrays1780.pdf

  But, as you learned, the problem was not so much with array processing as IF statement syntax and the need for quoting character strings in comparisons.

cynthia

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 766 views
  • 2 likes
  • 5 in conversation