DATA Step, Macro, Functions and more

If.Variable and Infile Statement

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

If.Variable and Infile Statement

Is it possible to use a first.variable statement and an infile?  I am tryin to sum up the album cost for each genre without using two data steps, currently the log says genre is unintialized.  Please help.

 


sas code.jpg

Accepted Solutions
Solution
‎11-06-2016 02:35 PM
Super User
Posts: 7,866

Re: If.Variable and Infile Statement

First. and last. are only available with a by statement. Variables in the by statement must be in the input dataset.

So the answer to your question is no.

Read the raw data into a dataset, then you can use by processing.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
PROC Star
Posts: 768

Re: If.Variable and Infile Statement

To use a first.Variable statement you have to have a by statement in your code?

Solution
‎11-06-2016 02:35 PM
Super User
Posts: 7,866

Re: If.Variable and Infile Statement

First. and last. are only available with a by statement. Variables in the by statement must be in the input dataset.

So the answer to your question is no.

Read the raw data into a dataset, then you can use by processing.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 11,343

Re: If.Variable and Infile Statement

Depending on what you actually want for your final output one of the report procedures such as Proc Report or Tabulate might be more in line. These both support creating group totals based and often do not require a separate sort step.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 214 views
  • 2 likes
  • 4 in conversation