DATA Step, Macro, Functions and more

How to create analysis variable at diff level than input file level?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 131
Accepted Solution

How to create analysis variable at diff level than input file level?

[ Edited ]

Hi everyone,

 

I'm wondering if anyone has suggestions for how I could create some meal-level and school-level variables from a food-level file. More specifically,

 

- Input file is a food item-level file of about 200,000 food items, where each record has variables to indicate the school ID, weekday (num, 1-5), the meal (lunch/breakfast), the food category (five categories), and multiple variables to indicate nutrient contents for that food item. Since these are food-level files, any school-level and menu-level variables repeat for each food within a school or day.  

 

How would I tell SAS to give me a variable of the minimum of a certain nutrient (ie lowest fat) at a specific school, on a day, during lunch meal, and within one food category.  What kind of functions would I use to get to this school-level variable?

 

Due to the size and structure of the input file, I'm opting not to do a basic proc transpose at the beginning of this work to convert the food level file to a school - level one. I'm wondering if there s other data/proc? step processing I can do to get to where I need to.

 

Would you let me know if I should clarify?

 

Thank you!

 


Accepted Solutions
Solution
‎01-27-2016 03:12 PM
Super User
Super User
Posts: 7,395

Re: How to create analysis variable at diff level than input file level?

Its hard to say, post a datastep with some test data,and what you want out.  There is min(), arrays, retain etc. any of which could work.

View solution in original post


All Replies
Solution
‎01-27-2016 03:12 PM
Super User
Super User
Posts: 7,395

Re: How to create analysis variable at diff level than input file level?

Its hard to say, post a datastep with some test data,and what you want out.  There is min(), arrays, retain etc. any of which could work.

Super User
Posts: 6,932

Re: How to create analysis variable at diff level than input file level?

[ Edited ]
proc sort
  data=have (
    where=(
      school="school" and
      weekday=X and
      category="category" and
      meal='Lunch'
    )
  )
  out=want
;
by nutrient_content;
run;

The first observation would then be the one with the lowest content for your selection.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 17,784

Re: How to create analysis variable at diff level than input file level?

You're looking for summary functions. 

 

SAS SQL and PROC MEANS are two standard way to obtain descriptive statistics and aggregate data.

☑ This topic is SOLVED.

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

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