From: =?ISO-8859-1?Q?Daniel_Fern=E1ndez?= on 7 Jan 2010 04:50 Bom-dia, como vai voc�? Why don�t you use the NMISS function? data questionaire; input id $8. md_1 md_2 md_3 md_4 md_5; cards; Zeca 1 . . 3.1 . Joao 3 2.5 3 3 3.5 Dulce 2 . 2 1 1 ; run; data wanted; set questionaire; if nmiss(of md_:) <=2 then Averagescore=mean(of md_:); run; Espero-o � �til. Daniel Fernandez. Barcelona 2010/1/6 Kim Fernandes <kim.fernandes(a)gmail.com>: > Hi there, > > I just learned about creating functions using proc fcmp that can be called > in the data step. I would like to pass a non-temporary array to a function, > but I do not think that this is allowed. Perhaps there is another way in > SAS to do this, or there is a workaround. Does anyone have any suggestions > for me? > > An example I've been playing with is below. I would like to take answers > from a questionnaire and calculate the average score if a certain number of > answers are provided. (i.e. if there are 5 questions and 2 are missing, > take the average, but if 3+ are missing, do not score the question). > > Thank you very much for your help. > > Kim > > ----------------------------------------------------------------- > > proc fcmp outlib = sasuser.funcs.jny; > function calc_se_scores(array_name[*],max_missing_allowed); > missing=0; > do i =1 to dim(array_name); > if array_name[i] = . then missing=missing +1; > end; > if missing <=max_missing_allowed then score=mean(of array_name{*}); > /*Error because array_name is not a temporary array*/ > return (score); > endsub; > options cmplib=sasuser.funcs; > > data j.data; > set j.data; > > array md{1:5} md_1 md_2 md_3 md_4 md_5; > array oh{1:4} oh_1 oh_2 oh_3 oh_4; > > md_score=calc_se_scores(md,2); /*Error because non-temporary > array*/ > oh_score=calc_se_scores(oh,1); > > run; >
From: Michael Raithel on 7 Jan 2010 08:15 Dear SAS-L-ers, Kim Fernandes posted the following: > > I just learned about creating functions using proc fcmp that can be > called > in the data step. I would like to pass a non-temporary array to a > function, > but I do not think that this is allowed. Perhaps there is another way > in > SAS to do this, or there is a workaround. Does anyone have any > suggestions > for me? > > An example I've been playing with is below. I would like to take > answers > from a questionnaire and calculate the average score if a certain > number of > answers are provided. (i.e. if there are 5 questions and 2 are > missing, > take the average, but if 3+ are missing, do not score the question). > > Thank you very much for your help. > Kim, I see that you got a solid answer from your SAS-L last-name synonym tw= in Daniel Fernandez that likely solves your problem. So, let me refer you = to an excellent paper on PROC FCMP that you might find useful since you are= just learning about this way-cool procedure: A Cup of Coffee and Proc FCMP: I Cannot Function Without Them, by Peter Ebe= rhardt http://support.sas.com/resources/papers/proceedings09/147-2009.pdf It is a great introductory treatment of PROC FCMP and may provide great ins= ights for you! Kim, best of luck in all of your SAS endeavors! I hope that this suggestion proves helpful now, and in the future! Of course, all of these opinions and insights are my own, and do not reflec= t those of my organization or my associates. All SAS code and/or methodolog= ies specified in this posting are for illustrative purposes only and no war= ranty is stated or implied as to their accuracy or applicability. People de= ciding to use information in this posting do so at their own risk. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Michael A. Raithel "The man who wrote the book on performance" E-mail: MichaelRaithel(a)westat.com Author: Tuning SAS Applications in the MVS Environment Author: Tuning SAS Applications in the OS/390 and z/OS Environments, Second= Edition http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=3D1&pc=3D58172 Author: The Complete Guide to SAS Indexes http://www.sas.com/apps/pubscat/bookdetails.jsp?catid=3D1&pc=3D60409 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Science has not yet mastered prophecy. We predict too much for the next year and yet far too little for the next 10. - Neil Armstrong +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
From: Muthia Kachirayan on 7 Jan 2010 12:03 Kim, You have received good advices. As far as I know, the FCMP function works only with _temporary_ array. You need to copy PDV vraiables to a temporary array before passing to FCMP function. See the Example 3: Executing Proc STANDARDIZE on Each Row of a Data Set in SAS Docs. Another alternative way is to use read_array() function available in FCMP. This is used to pass the entire data set and use it as a matrix of rows and columns to manipulate the elements. After the processing, the resulting matrix can be accessed as another data set by using write_array() function. Muthia Kachirayan On Wed, Jan 6, 2010 at 6:19 PM, Kim Fernandes <kim.fernandes(a)gmail.com>wrote: > Hi there, > > I just learned about creating functions using proc fcmp that can be called > in the data step. I would like to pass a non-temporary array to a > function, > but I do not think that this is allowed. Perhaps there is another way in > SAS to do this, or there is a workaround. Does anyone have any suggestions > for me? > > An example I've been playing with is below. I would like to take answers > from a questionnaire and calculate the average score if a certain number of > answers are provided. (i.e. if there are 5 questions and 2 are missing, > take the average, but if 3+ are missing, do not score the question). > > Thank you very much for your help. > > Kim > > ----------------------------------------------------------------- > > proc fcmp outlib = sasuser.funcs.jny; > function calc_se_scores(array_name[*],max_missing_allowed); > missing=0; > do i =1 to dim(array_name); > if array_name[i] = . then missing=missing +1; > end; > if missing <=max_missing_allowed then score=mean(of array_name{*}); > /*Error because array_name is not a temporary array*/ > return (score); > endsub; > options cmplib=sasuser.funcs; > > data j.data; > set j.data; > > array md{1:5} md_1 md_2 md_3 md_4 md_5; > array oh{1:4} oh_1 oh_2 oh_3 oh_4; > > md_score=calc_se_scores(md,2); /*Error because non-temporary > array*/ > oh_score=calc_se_scores(oh,1); > > run; >
|
Pages: 1 Prev: book: Making Data Talk Next: how can you get counts using first .and last. in datastep |