Practice Question
data word.new;
length word $7;
amount=4;
If amount=4 then word ='four';
else if amount=7 then word = 'seven';
else word='NONE!!!!';
amount=7;
run;
Answer
Amount Word
7 FOUR
Can somebody please explain the rational behind the answer.
There is a concept of PDV in SAS, the Program Data Vector is a logical area of memory that is created during the data step processing. SAS builds a SAS dataset by reading one observation at a time into the PDV and, unless given code to do otherwise, writes the observation to a target dataset.So here in the beginning as per the data step, the amount=4; then the same values is used to fill the value of variable amount=4, then the if/then step is read and since amount=4 when its read the word variable is set to FOUR, then again the amount variable is read again and this time since the value is 7 the amount of 4 is overwritten with 7. And since after this there is no if/then the same values will remain and are output.
The code as shown has an error in the IF condition and likely would error out.
@swayto wrote:
Practice Question
data word.new;
length word $7;
amount=4;
If amount=4 then word ='four';
else amount=7 then word = 'seven';
else word='NONE!!!!';
amount=7;
run;
Answer
Amount Word
7 FOUR
Can somebody please explain the rational behind the answer.
Sorry else if
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.