Desktop productivity for business analysts and programmers

Getting some basic code to run (N00b question)

Reply
N/A
Posts: 0

Getting some basic code to run (N00b question)

I'm fairly new to enterprise Guide, and don't have a manual to work with.

I'm trying to run some code that does not use something like proc glm or proc mixed etc, this kind of code is easy to do in maple or R, but I've just got no idea why SAS freaks out.

r = 4;
df1 = 5-1;
df2 = (r-1)*(5-1);
c = css(4,5,6,7,8);
ncp = r*c/sigma2;
fcrit = finv(0.95,df1,df2);
power = 1-probf(fcrit,df1,df2,ncp);
proc print;
run;

The reason I'm using it in SAS is I'm trying to take advantage of the css() function which I don't believe exists in alternative software.

thanks!
Occasional Contributor
Posts: 8

Re: Getting some basic code to run (N00b question)

without knowing anything about what your formulaes are doing and if your use of CSS makes sense, I can suggest you put it into a data step to make it work:

data calcs;
r = 4;
df1 = 5-1;
df2 = (r-1)*(5-1);
c = css(4,5,6,7,8);
ncp = r*c/sigma2;
fcrit = finv(0.95,df1,df2);
power = 1-probf(fcrit,df1,df2,ncp);
run;
proc print data=calcs;
run;

it's not really using much of sas's power, but I guess it'll work for what you need.
N/A
Posts: 0

Re: Getting some basic code to run (N00b question)

Goodpeace,

Thanks for the suggestion. I see that I really need to buy a manual or something, as my problem is primarily simple lack of knowledge about the SAS language... It wouldn't have occurred to me to treat my calculations as a data set.

As for the SAS manuals online... None of them really have headings like "So you just want to SAS to add 5+5..."
Super Contributor
Super Contributor
Posts: 3,174

Re: Getting some basic code to run (N00b question)

Kind suggestion - Google search below:

sas for dummies site:amazon.com

Scott Barry
SBBWorks, Inc.
SAS Super FREQ
Posts: 8,819

Re: Getting some basic code to run (N00b question)

Hi:
If you read up on SAS basic concepts, you will soon learn that SAS has 2 basic modes of operation: "canned" procedures which do specific things (like getting one way frequency tables or generating summary statistics or creating cross-tabular analysis) and then the DATA step programming language. (That is an over-simplification, but it is one way to start thinking about what road you're on).

So, the "canned" procedures can do a lot and when combined with the powerful PROC SQL, you can do some data manipulation and querying and subsetting of existing data before you pass the data off to the analytic procedures for processing or to the graph procedures for graphing. When you use the tasks and wizards in SAS Enterprise Guide, EG is acting as a "front end" GUI interface -- mostly between you and the "canned" procedures. (Actually, there are times and places where EG can generate program code (DATA step) -- but I'm keeping things simple here.)

The minute you want to do something "out of the box" or "not in the can", such as writing your own formulas or using functions, then you are into the world of DATA step programming. You have 2 choices with a DATA step progarm -- create an output dataset suitable for printing or use the programming language and do NOT create a dataset. Consider these 2 versions of your program. The first one is the version suggested by GoodPeace:
[pre]
data calcs;
r = 4;
df1 = 5-1;
df2 = (r-1)*(5-1);
c = css(4,5,6,7,8);
ncp = r*c/sigma2;
fcrit = finv(0.95,df1,df2);
power = 1-probf(fcrit,df1,df2,ncp);
run;

proc print data=calcs;
title 'what is in dataset CALCS?';
run;
[/pre]

and the output from that program would be (showing the PROC PRINT in LISTING or Text view):
[pre]
what is in dataset CALCS?

Obs r df1 df2 c ncp sigma2 fcrit power

1 4 4 12 10 . . 3.25917 .
[/pre]

Note how each statement created a variable (column) and the value that was calculated is shown for Observation 1 -- that's because without any input data, this program only executes for 1 time. If you had an INPUT dataset to the program, the programs statements would execute one time for every observation in the INPUT dataset (unless you programmed execution differently).

If you ONLY wanted the numbers, for example, you really only wanted the value for FCRIT, then you could have just written a DATA _NULL_ program, which allows you to use the programming language and the functions, but does NOT create an OUTPUT dataset. So this version of the program has a PUT _ALL_; statement which writes the variable information that's been calculated into the SAS log:
[pre]
data _null_;
r = 4;
df1 = 5-1;
df2 = (r-1)*(5-1);
c = css(4,5,6,7,8);
ncp = r*c/sigma2;
fcrit = finv(0.95,df1,df2);
power = 1-probf(fcrit,df1,df2,ncp);
put _all_;
run;
[/pre]

...and the output, shown in the SAS log, is:
[pre]
311 data _null_;
312 r = 4;
313 df1 = 5-1;
314 df2 = (r-1)*(5-1);
315 c = css(4,5,6,7,8);
316 ncp = r*c/sigma2;
317 fcrit = finv(0.95,df1,df2);
318 power = 1-probf(fcrit,df1,df2,ncp);
319 put _all_;
320 run;

NOTE: Variable sigma2 is uninitialized.
r=4 df1=4 df2=12 c=10 ncp=. sigma2=. fcrit=3.2591667269 power=. _ERROR_=0 _N_=1
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line)Smiley SadColumn).
1 at 316:10 1 at 318:10 1 at 318:11
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
[/pre]

Now this is interesting....because now you have just the FCRIT number that you can do something with. But you also see that you referenced SIGMA2 as a variable in one of your formulas, but the log message is telling you that it did not find a value for SIGMA2 when it performed the calculation.

Scott suggested that you look at support.sas.com for documentation...and that is a good idea. Depending on what you want/need to do, you might want to start with this "concepts" site:
http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a001331149.htm

It will not refer to Enterprise Guide much, as the concepts are all about what's under the GUI interface. For books about using EG specifically, these are good books:
https://support.sas.com/pubscat/bookdetails.jsp?pc=62824
https://support.sas.com/pubscat/bookdetails.jsp?catid=1&pc=61861

cynthia
N/A
Posts: 0

Re: Getting some basic code to run (N00b question)

Cynthia@sas

Ah, right. I forgot that Enterprise guide is a front end for the SAS language, and hence isn't necessarily the same environment such as R. Your points were quite helpful.

At this point, I don't need to get too fancy with my work, I'm simply using SAS for a Master's level experimental design course. (PROC SQL I could see using something like that in my day job!)

sbb, thanks for the suggestion! Message was edited by: Max Nevill
Super Contributor
Super Contributor
Posts: 3,174

Re: Getting some basic code to run (N00b question)

Suggest you post a reply and paste in your SAS log - also consider that the SAS support http://support.sas.com/ has SAS software documentation, along with supplemental technical / conference reference material.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search arguments, this topic / post:

enterprise guide documentation site:sas.com

sas eg site:sas.com
Ask a Question
Discussion stats
  • 6 replies
  • 199 views
  • 0 likes
  • 4 in conversation