Help using Base SAS procedures

Query to find Freq

Reply
N/A
Posts: 0

Query to find Freq

Jacob,

Query to set a Freq, description is as follows,i require the code to set Freq as shown in Freq coloumn

Time Volatge Flag Freq
1 230 0 1
2 233 0 0
3 231 0 0
4 215 1 1
5 211 1 0
6 242 2 1
7 248 2 0
8 246 2 0


Flag parameter used is as per values of voltage for example if voltage is>240 its 2 and if voltage is < 216 then 1 else 0,but i require the code to find out "freq"which is such that if for time slot 1 voltage is 230 and its flag is 0 then freq is 0,but in next slot if value is in that range>216 and <240 then it shld be 0,and again if in next slot if the value of voltage is 242 then freq shld be 1,then again if it continues in that range then 0,and if next slot if value is less than 216 or in that range then it shld change to 1.


Thanks,
Super User
Posts: 5,254

Re: Query to find Freq

I'm not sure if I can follow you logic, but I'm pretty sure you can solve this using data step programming with RETAIN and/or LAG().
/Linus
Data never sleeps
Super Contributor
Super Contributor
Posts: 3,174

Re: Query to find Freq

Agreed with Linus, straighforward DATA step programming using a sorted input SAS file will work. A starting point link is provided below -- also, you can use the SEARCH facility at the SAS support http://support.sas.com/ website to locate SAS-hosted documentation and supplemental technical/conference topic-related reference. Within the DATA step area, as Linus mentioned, related SAS statements are RETAIN and using the LAG function, or possibly FIRST. and/or LAST. in your DATA step program. You should also consider adding the SAS PUTLOG statement below periodically (during program development and testing) in order to dump SAS variable value conditions as you discover more about the DATA step programming world:

PUTLOG '>DIAG-nn' / _ALL_; * set nn to unique values to see in your log ;


Scott Barry
SBBWorks, Inc.

Introduction to DATA Step Processing
http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001302699.htm
Ask a Question
Discussion stats
  • 2 replies
  • 101 views
  • 0 likes
  • 3 in conversation