LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2003, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 19 Jun 2003 18:19:46 -0400
Reply-To:     Richard Graham <richardwgraham@earthlink.net>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
Comments:     To: STR <setar@MINDSPRING.COM>
From:         Richard Graham <richardwgraham@EARTHLINK.NET>
Organization: Glencairn Consulting Group
Subject:      Re: SAS Loop Logic Question
Comments: To: SAS-L@LISTSERV.VT.EDU
Content-Type: text/plain; charset="iso-8859-1"

Here's one approach......

/*Get the contents of the data set*/

proc contents data = wa.integral_sales out=work.contents(keep=name varnum) noprint;

run;

/* you will probably want to exclude your identifying variables from the contents */

proc sort data=work.contents;

where name not in ('id1' 'id2' etc);

by varnum;

run;

/*This next data step creates macro variables from the contents data set and counts how many there are */

data _null_;

set work.contents end=eof;

call symput('v'||trim(left(put(_n_,best.))),name);

if eof then call symput('totv',trim(left(put(_n_,best.))));

run;

/*This step allows you to reference the macro variables (indirect variable references) in the data step */

%macro test;

data libname.dsname_a;

set libname.dsname;

array vars(&totv) %do _i = 1 %to &totv; &&v&_i %end;;

.....

run;

%mend test;

%test;

HTH

Richard Graham Vice President Glencairn Counsulting Group, Inc.

----- Original Message ----- From: "STR" <setar@MINDSPRING.COM> To: <SAS-L@LISTSERV.VT.EDU> Sent: Thursday, June 19, 2003 5:35 PM Subject: Re: SAS Loop Logic Question

> I may have over simplified my dataset for the purposes of this > discussion. Actually, there are approx. 1000 variables I need to > analye for each observation. Unfortunately, the variables are not > numbered in succession. They are unique 5 digit numbers. When > initializing my array, is there an easier solution outside of listing > all of my variables? Could I make a dataset containing the variable > names only and somewhow use that as input to the initialiation of the > array? Of course it sounds logical, but I wouldn't know how to tackle > this. > > I am greatly for the expertise you may offer. > > rjf2@CDC.GOV (Fehd, Ronald J. PHPPO) wrote in message news:<9D17D648E4EBD311AD45009027D0DF9305002BBF@MCDC-ATL-64>... > > > From: STR [mailto:setar@MINDSPRING.COM] > > > I am in need of devising a loop to perform the following > > > given the sample dataset below: > > > yr1 yr2 yr3 > > > > > > EMP1 10 5 6 > > > EMP2 2 7 5 > > > EMP3 3 3 3 > > > > > > (I have simplefied the dataset for practical purposes) > > > > > > For each EMP, I want to add up the ratings for all 3 years. > > > If the sum of all 3 years for that EMP is greater than 10, > > > then I want to write out the highest value to another data > > > set. Then I want perform the same operation, eliminating the > > > highest value identified in the previous step from the > > > calculation. I want to continue this loop until the > > > remaining values left to calculate aggregate to a value less than 10. > > > > you are in need of a major RTFM session. > > the functions you are looking for are > > sum(of Years(*)) > > and similarly: > > max(of Years(*)) > > > > based on your simplified data set structure > > you'll need to define an array: > > array Year(3); > > if your year variables are not contiguous in the data set > > or have different prefixes than Year > > then you will have to list them: > > > > DATA LESS-THAN-10 > > EXACTLY-10 > > MORE-THAN-10 > > MAX (keep = Max Fred Georgette) > > ; > > array Year(3) year1 yr2 yer3; > > drop I; > > > > something like: > > SumYears = sum(of Years(*)); > > if SumYears gt 10 then output MORE-THAN-10; > > Max = max(of Years(*)); > > if Max gt 10 then output MAX; > > do I = 1 to dim(Years);*...; > > > > that should get you going. > > > > Ron Fehd the macro maven CDC Atlanta GA USA RJF2@cdc.gov > > > > RTFM: I'm an engineer, I don't get paid to know, > > I get paid to know where to look it up. > > RTFM: Read The Finite Manual. > > > > RTFM: I'm The Maven I don't get paid to know, > > I volunteer to tell other people what to look up. > > RTFM: Read The Finite Manual. >


Back to: Top of message | Previous page | Main SAS-L page