BookmarkSubscribeRSS Feed
zhongnanzi
Calcite | Level 5

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. 

8 REPLIES 8
novinosrin
Tourmaline | Level 20

DATA = Production;

SET Factory.Production;

Total = Sum(of Daily-Daily365);

If Month = January THEN Current = Yes;

RUN;

zhongnanzi
Calcite | Level 5

Thanks!!

zhongnanzi
Calcite | Level 5

One more question,what‘s wrong with this statement?Total = Sum(of Daily-Daily365);

mkeintz
PROC Star

@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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

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;
ChrisNZ
Tourmaline | Level 20

DATA = Production;

SET Factory.Production ;

Total = Sum(of Daily-Daily365);

If Month = January THEN Current = Yes;

RUN ;

zhongnanzi
Calcite | Level 5

Thanks!

Tom
Super User Tom
Super User

@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;

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

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
  • 8 replies
  • 1342 views
  • 1 like
  • 6 in conversation