BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AbhilashS
Fluorite | Level 6

Hi there

I am trying to create the following type of table in SAS manually and then practice getting means, standard deviations, and interquartile ranges from the data and table. I am not sure what type of code to use to efficiently input the data into SAS without having to repeatedly key in each value.

Screen Shot 2020-05-11 at 14.38.56.png


Thank you for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @AbhilashS and welcome to the SAS Support Communities!

 

You can create the dataset as PaigeMiller suggested or, e.g., like this:

data have;
hours=4+_n_;
input n @@;
cards;
3 8 20 11 6 2
;

Then apply PROC UNIVARIATE to dataset HAVE using the FREQ statement

freq n;

(or freq frequency; if you used this variable name in the INPUT statement) to compute the statistics.

 

Alternatively, create the dataset with only one variable (hours), but with 50 observations rather than 6, and then omit the FREQ statement in the analysis:

data have;
hours=4+_n_;
input _n_ @@;
do _n_=1 to _n_;
  output;
end;
cards;
3 8 20 11 6 2
;

 

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Here's how you input the first two rows

 

data have;
     input hours frequency;
     cards;
5 3
6 8
;

It's not clear what you mean by "without having to repeatedly key in each value"? Is the data in a file (text file, csv file, excel file) somewhere? What does the word "repeatedly" refer to? Why do you think this would have to be done "repeatedly"?

--
Paige Miller
AbhilashS
Fluorite | Level 6
I am going to try this and then run the statistics and see if the answers match. I was worried that if I try to get the 'median' value for hours for instance, it might not realize each different hour have a number of responses.
be right back!
FreelanceReinh
Jade | Level 19

Hi @AbhilashS and welcome to the SAS Support Communities!

 

You can create the dataset as PaigeMiller suggested or, e.g., like this:

data have;
hours=4+_n_;
input n @@;
cards;
3 8 20 11 6 2
;

Then apply PROC UNIVARIATE to dataset HAVE using the FREQ statement

freq n;

(or freq frequency; if you used this variable name in the INPUT statement) to compute the statistics.

 

Alternatively, create the dataset with only one variable (hours), but with 50 observations rather than 6, and then omit the FREQ statement in the analysis:

data have;
hours=4+_n_;
input _n_ @@;
do _n_=1 to _n_;
  output;
end;
cards;
3 8 20 11 6 2
;

 

AbhilashS
Fluorite | Level 6

Thank you both PaigeMiller and FreelanceReinhard. I tried the last code and found it a best fit. I am only starting so I apologize for some nonsensical questions.  The answers matched what I was looking for from 50 responses.

 

Screen Shot 2020-05-11 at 16.01.17.png

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 524 views
  • 0 likes
  • 3 in conversation