The following SAS code includes three mistakes that would stop it from working. Identify each of the mistakes:
DATA = Production;
SET Factory.Production
Total = Sum(of Daily-Daily365);
If Month = January THEN Current = Yes;
RUN
(30 points)
Thank you for proving me an answer.
DATA = Production;
SET Factory.Production;
Total = Sum(of Daily-Daily365);
If Month = January THEN Current = Yes;
RUN;
Thanks!!
One more question,what‘s wrong with this statement?Total = Sum(of Daily-Daily365);
@zhongnanzi wrote:
One more question,what‘s wrong with this statement?Total = Sum(of Daily-Daily365);
Look carefully at the statement. Tell us what you THINK it means.
Test it.
With a data step like:
data example; input x x1 x2 x3; total = sum(of x-x3); datalines; 1 2 3 145678 ; run;
Log:
72 data example; 73 input x x1 x2 x3; 74 total = sum(of x-x3); --- 71 ERROR: Missing numeric suffix on a numbered variable list (x-x3). ERROR 71-185: The SUM function call does not have enough arguments. 75 datalines; NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set USER.EXAMPLE may be incomplete. When this step was stopped there were 0 observations and 5 variables. WARNING: Data set USER.EXAMPLE was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 77 ;
Compare with:
data example; input x x1 x2 x3; total = sum(of x -- x3); total2 = sum(of x1 - x3); total3 = sum(of x:); datalines; 10 20 30 145 ; run;
DATA = Production;
SET Factory.Production ;
Total = Sum(of Daily-Daily365);
If Month = January THEN Current = Yes;
RUN ;
Thanks!
@zhongnanzi wrote:
The following SAS code includes three mistakes that would stop it from working. Identify each of the mistakes:
DATA = Production;
SET Factory.Production
Total = Sum(of Daily-Daily365);
If Month = January THEN Current = Yes;
RUN
(30 points)
Thank you for proving me an answer.
Not the best worded question. When confronted with poorly worded questions I like to include the assumptions that I have to make to remove the confusion.
So assuming that this was intended to be a complete step then I would assume that they meant it to be a data step.
So the first line should not have the equal sign.
The second and last line should have ending semi-colons.
If you correct those three mistakes then the code should run. But it probably does not do what was intended.
In the third line is valid code but the SUM() function is not needed because you are passing it only one value, the difference between the two variables DAILY and DAILY365. So if we assume that the intend was to sum multiple variables then perhaps the intend was to have a variable list instead of a subtraction. In which case we need something like DAILY1-DAILY365.
The fourth line is also valid code, but perhaps not what was intended. Right now it is comparing two variables, MONTH and JANUARY, and when they match it is replacing the value of CURRENT with the value of YES. If we assume what was wanted was to treat January and Yes as constant/literal strings instead of variable names then they need to be enclosed in quotes.
For more analysis we would need to know if the libref FACTORY had been assigned and if the dataset PRODUCTION was in it. And what variables PRODUCTION contains. And information about how those variables were defined (type/length/format attached) and what they contained. For example is MONTH a variable? Is it character variable? A numeric variable? If numeric does it have a date type format attached? Or user defined format that makes the values look like January? Does the variable CURRENT already exist? Is it numeric or character? Is it long enough to store the three bytes needed to store Yes?
Corrected code.
data production;
set factory.production;
total = sum(of daily1-daily365);
if month = 'January' then current = 'Yes';
run;
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 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.