BookmarkSubscribeRSS Feed
Fred_Gavin
Calcite | Level 5
Really need help for the problem as below.
This is the pseudo data table.
For three stocks, I wanna extract the data between 1 and 2. Dots are the missing values.
Note that For Stock B, 2 does not appear on the table. but we still need to select those between date 2.4 and 2.7.

I am looking for a generalized codes for performing the selection, as my real data consists of hundreds of stocks.

Thank you so much first !!!

DATE STOCK PRICE Volume first/last
1.1 A . .
1.2 A . .
1.3 A . .
1.4 A 0.5 200 1
1.5 A 0.6 1000
1.6 A . .
1.7 A 0.5 300 2
1.8 A . .
1,9 A . .
2.1 B . .
2.2 B . .
2.3 B . .
2.4 B 0.75 400 1
2.5 B 0.6 2000
2.6 B . .
2.7 B 1..5 300
3.1 C . .
3.2 C . .
3.3 C 2 5000 1
3.4 C 1.5 2000
3.5 C 2 1000
3.6 C 1.75 3000 2
3.7 C 1.8 5000
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Use SAS PROC SUMMARY with MAX and MIN to get your CLASS variable value ranges for selection, creating a separate SAS file. Then using a DATA step and your data file sorted appropriately, MERGE (with a BY on your CLASS variables) back in the MIN/MAX range file and use IF THEN OUTPUT; to subset your data file.

Scott Barry
SBBWorks, Inc.
GertNissen
Barite | Level 11
I think this will do the job... you will need to change how date is read etc, but you have something to work with (if I understand your question correct)

[pre]data input;
infile datalines missover dlm=" ";
input DATE :$3. STOCK $ PRICE Volume first_last;
datalines;
1.1 A . .
1.2 A . .
1.3 A . .
1.4 A 0.5 200 1
1.5 A 0.6 1000
1.6 A . .
1.7 A 0.5 300 2
1.8 A . .
1.9 A . .
2.1 B . .
2.2 B . .
2.3 B . .
2.4 B 0.75 400 1
2.5 B 0.6 2000
2.6 B . .
2.7 B 1.5 300
3.1 C . .
3.2 C . .
3.3 C 2 5000 1
3.4 C 1.5 2000
3.5 C 2 1000
3.6 C 1.75 3000 2
3.7 C 1.8 5000
;run;

data result(drop=flag);
retain flag 0;
set input(sortedby=stock);
by stock;
if first.stock then flag=0;
if first_last = 1 then flag=1;
if flag = 1 then output;
if first_last = 2 then flag=0;
run;[/pre]

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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