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;
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
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
The only prroblem I see is the absence of quotes around f and m in your if statements. PG
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
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
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.
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.