BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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,
2 REPLIES 2
LinusH
Tourmaline | Level 20
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
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 776 views
  • 0 likes
  • 3 in conversation