BookmarkSubscribeRSS Feed
jcis7
Pyrite | Level 9

Hi,

 

I have the following data:

 

data have;

infile datalines missover;

input buildingname $10. buildingtype $8. responded $1. jurisdictn $9. enr 3 ;

cards;

happy days privateY nottingha 100

learning public N nottingha

buildingbl privateY nottingha 55

montessori privateN nottingha

bean stalk privateY brunswick 55

learning private Y brunswick 22

early lear privateY brunswick 66

childtime private N brunswick

risingstar public N brunswick

doodlebugs public Y brunswick 34

 

;

run;

 

I couldn't fingure out how to get the enrollment to show in the datatable using the infile statement

Here are the calculations I need to do -- summarize by jursidiction and buldingtype: sum of enrollment divided by total # that responded 'Y'
Calculations:

jurisdiction      private                    public
nottingham    (100+55)/2       
brunswick     (55+22+255)/3            34/1


Final results:
jursidiction     private    public
nottingham     77.5            
brunswick       110.7    34.0

 

 

 

 

How would I do that?  Thanks!  I'm on Base SAS 9.4

 

2 REPLIES 2
art297
Opal | Level 21

It would be easier to do if you entered your data in a format that would make it easier for SAS to read. However, given the way it was entered (at least for the data you showed in your example), the following would work:

 

data have;
  infile datalines truncover;
  informat buildingname $10.;
  informat buildingtype $8.;
  informat responded $1.;
  informat jurisdictn $9.;
  input @;
  _infile_=tranwrd(_infile_,'Y', ' Y');
  _infile_=tranwrd(_infile_,'N', ' N');
  _infile_=tranwrd(_infile_,'public', ' public');
  _infile_=tranwrd(_infile_,'private', ' private');
  input buildingname & buildingtype responded jurisdictn enr;
datalines;
happy days privateY nottingha 100
learning public N nottingha
buildingbl privateY nottingha 55
montessori privateN nottingha
bean stalk privateY brunswick 55
learning private Y brunswick 22
early lear privateY brunswick 66
childtime private N brunswick
risingstar public N brunswick
doodlebugs public Y brunswick 34
;

proc means data=have mean;
  class jurisdictn buildingtype;
  var enr;
run;

Art, CEO, AnalystFinder.com

 

CliftonDenning
Obsidian | Level 7

I'm sure there are others who can do it better, but is it possible to santaize your input data? It looks to be a bit all over the place making it hard for SAS to differentiate where one variable ends and the next begins. You could either space it per the values in your input statement, or add a delimiter like below:

 

data have;
infile cards missover dlm="|";
length buildingname $10. buildingtype $8. responded $1. jurisdictn $11. enr 3. ;

input buildingname buildingtype responded jurisdictn enr ;
cards;
happy days|private|Y|nottingha|100
learning|public|N|nottingha|0
buildingbl|private|Y|nottingha|55
montessori|private|N|nottingha|
bean stalk|private|Y|brunswick|55
learning|private|Y|brunswick|22
early lear|private|Y|brunswick|66
childtime|private|N|brunswick|
risingstar|public|N|brunswick|
doodlebugs|public|Y|brunswick|34
;
run;

 

 

As for summarizing you could use proc sql or proc report to create a summary table of the values once they are all in the table. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 2 replies
  • 780 views
  • 2 likes
  • 3 in conversation