Help using Base SAS procedures

do loops or do until with the by statement

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

do loops or do until with the by statement

Hi, 

 

I have a dataset with some accounts and every account may have more than one observation in the data. 

Assuming a scenarion, if one of the account has 10 observations and every observation has a different stat_code which is one of the variables along with stat_dt

 

What i want to do is to go through the first entry till the last entry of the duplicate accounts and then apply a condition 

on stat_code, something like if substr(stat_code, 4,1) = 'S' and every time it finds that between the first and the last observation, it outputs that entry into a seperate dataset. 

 

Will appreciate some direction and help!

 

--Tej


Accepted Solutions
Solution
‎01-28-2017 02:29 PM
Super User
Posts: 19,800

Re: do loops or do until with the by statement

Posted in reply to BhararaTej

I don't see anything to indicate the need for something besides a simple filter. 

SAS loops through each one in the dataset by default, and you can implement BY group processing if it's needed. 

 

See the tutorial here in how to filter

http://support.sas.com/training/tutorial/studio/filter-tables.html

View solution in original post


All Replies
Respected Advisor
Posts: 4,922

Re: do loops or do until with the by statement

Posted in reply to BhararaTej

Please provide sample (in machine readable format) input and expected output data, for us to work on.

PG
Occasional Contributor
Posts: 9

Re: do loops or do until with the by statement

Here is a sample input. I want to go through each and every account as you see there are duplicate and search for where substr(status_code,4,1) = 'L' and where ever it finds that it outputs that record.

 

AccountStatus CodeDate
11112XYZS10th Jan 2011
11112HGJL11th Jan 2011
11112FTYJ12th Jan 2011
11112LKIL13th Jan 2011
234322PLKS6th June 2016
234322RTYZ7th June 2016
234322KJLL8th June 2016
234322IUYL9th June 2016
234322RTYZ10th June 2016
234322RTYZ11th June 2016
234322RTYZ12th June 2016

 

 

Output should look like below as it output recoed whereever it finds that string

 

11112HGJL11th Jan 2011
11112LKIL13th Jan 2011
234322KJLL8th June 2016
234322IUYL9th June 2016
Super User
Posts: 19,800

Re: do loops or do until with the by statement

Posted in reply to BhararaTej

Did you try anything? This should be really straight forward, especially after the video example.

Solution
‎01-28-2017 02:29 PM
Super User
Posts: 19,800

Re: do loops or do until with the by statement

Posted in reply to BhararaTej

I don't see anything to indicate the need for something besides a simple filter. 

SAS loops through each one in the dataset by default, and you can implement BY group processing if it's needed. 

 

See the tutorial here in how to filter

http://support.sas.com/training/tutorial/studio/filter-tables.html

Occasional Contributor
Posts: 9

Re: do loops or do until with the by statement

Posted in reply to BhararaTej
I know i can do the where clause but I am also looking to figure out a way to do this by "by processing"
Super User
Posts: 11,343

Re: do loops or do until with the by statement

Posted in reply to BhararaTej

BY processing usually means there is something special done with each level or group, or combination of levels, of the By variable(s).

You do not show anything that is dependent on a group of values.

I could add a by statement to the datastep but it wouldn't add any value. If you wanted to know something like the order number within the account value then that could use by processing. 

 

If there is something else other than the data shown and the rule  and desired results then there may be some value to adding by group processing.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 225 views
  • 0 likes
  • 4 in conversation