BookmarkSubscribeRSS Feed
imanojkumar1
Quartz | Level 8

I have data set which has daily observations of X Y cordinates. The sample dats is available at the bottom:

 

I have plotted some of the data and plots are shown below:

 

sample plots

 

 

What I want to do is to find the mid points and highest points on the curves as shown in the pictures.

 

One plot is for data on 28Sep16 and other on 17Nov16 (X, Y cords).

 

I want to know the different in hieghts on these points (top and mid). Y can be treated as height in 'mm'.

 

Can someone please help? Thanks.

 

 

DATA:

 attached as code12.txt

18 REPLIES 18
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Please do not post links to websites in your post.  Post test data as text in the form of a datastep in the post.  You can follow this guidance if you need help to get this:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

For your question, the graph is merely a representation of your data, hence any value you need to arrive at should be calculatable from the data.  For instance, your first "point" would be max(of variable plotted on Y axis).  The next point maybe mean/median of the values on the Y axis (not entirely sure from what you posted), and the final point would be mean/median of X axis variable.  So you can use proc means to get all of the above information.

imanojkumar1
Quartz | Level 8

Since data size is larger than allowable limit of 200,000, I am attaching it in data step in .txt file.

 

Please note that date format (Date18.) is not correct format 😞 for the datetimestamp type i have in data.

 

Thanks.

Ksharp
Super User

Post data here better or attach a txt file.

You can use DIF() to get it. if dif() change from positive into negative, then it is highest  value.

http://blogs.sas.com/content/iml/2013/08/28/finite-diff-estimate-maxi.html

 

 

If dif() = next dif() then it shoulde be mid value.

 

imanojkumar1
Quartz | Level 8
Hi Ksharp I have attacted the data as data step in text file above with my question. Thanks for suggetion. Please note that date format (Date18.) is not correct format for the datetimestamp type I have in data.
imanojkumar1
Quartz | Level 8

I am trying something lile this one..... but I dont know how to find other mid points and calculate difference in Heights at those coordinates...

 

PROC SQL;
     CREATE VIEW WORK.XYData AS
           SELECT T.X, T.Y
     FROM mydata as T
;
QUIT;

PROC SQL;
SELECT MAX(Y) FORMAT=6.2 LABEL='MAXY' INTO : MAXY FROM
WORK.XYData ;
QUIT;

DATA WORK.MAXY ; SET WORK.XYData; Where Y=&MAXY. ; RUN; PROC SQL; SELECT X FORMAT=6.2 LABEL='MAXY_X' INTO : MAXX FROM WORK.MAXY ; QUIT; /* DATA WORK.MINY_X ; SET WORK.XYData ; Where Y>0. ; RUN;*/ PROC SQL; SELECT MIN(Y) FORMAT=6.2 LABEL='MINY' INTO : MINY FROM WORK.XYData Where Y>=0.; QUIT; %put &MINY.; DATA WORK.MINY_X ; SET WORK.XYData; Where Y=&MINY. ; RUN; PROC SQL; SELECT X FORMAT=6.2 LABEL='MINY_X' INTO : MINY_X FROM WORK.MINY_X ; QUIT; %put &MINY_X; /* End of custom user code. */ SYMBOL1 INTERPOL=SM0 HEIGHT=10pt VALUE=NONE LINE=1 WIDTH=2 CV = _STYLE_; Axis1 STYLE=1 WIDTH=1 ORDER=(-70000 TO 40000 BY 5000) MINOR=NONE; Axis2 STYLE=34 WIDTH=1 ORDER=-20000 TO 140000 BY 5000 MINOR=NONE LABEL=NONE; TITLE; TITLE1 "Line Plot"; FOOTNOTE; FOOTNOTE1 ""; PROC GPLOT DATA = WORK.XYData ; PLOT Y * X / VAXIS=AXIS1 HAXIS=AXIS2 NOFRAME LHREF=1 CHREF=BLACK LVREF=1 CVREF=BLACK VREF=0 VREF=-10000 VREF=&MAXY. HREF=&MAXX. HREF=&MINY_X. /* End of custom user code. */ ; RUN; QUIT; TITLE; FOOTNOTE; GOPTIONS RESET = SYMBOL;

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

You have overcomplicated things a bit there.  First some tips - I would suggest move to a modern graphing system - SGPLOT and Graph Template Language.  I would also suggest code formatting, consitent indentation/casing and such like to make code readable.  

Now your problem can simplfy to, get values you need, add them to the data, overlay the points you want:

proc sql;
  create table G as
  select  A.*,
          B.MAX_Y,
          B.MAX_X,
          B.MIN_Y
  from    WORK.XYDATA A
  left join (select MAX(Y) as MAX_Y,
                    MAX(X) as MAX_X,
                    MIN(Y) as MIN_Y
             from   WORK.XYDATA) B
  on      1=1;
quit;
             
title1 "Line Plot";
footnote;
footnote1 "";

proc sgplot data=g;
  series y=y x=x;
  scatter y=max_y / datalabel=max_y;
  scatter y=max_x / datalabel=max_x;
  scatter y=min_y / datalabel=min_y;
run;

Not tested this of course, but something like that should work.  The scatter puts a point at max value and the datalabel tells it to add teh value as the label.  There are many options with GTL/Sgplot.

imanojkumar1
Quartz | Level 8

I got errors...

 

35           scatter y=MAX_Y / datalabel=MAX_Y;
                            _
                            79
                            76
36           scatter y=MAX_X / datalabel=MAX_X;
                            _
                            79
                            76
37           scatter y=MIN_Y / datalabel=MIN_Y;
                            _
                            79
2                                                          The SAS System                           13:59 Tuesday, November 22, 2016

                            76
ERROR 79-322: Expecting a X.
ERROR 76-322: Syntax error, statement will be ignored.

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, as mentioned, not tested.  The error tells you what you need to know:

scatter y=MAX_Y x=x / datalabel=MAX_Y;
Ksharp
Super User

This could give a start.

 

data x;
infile '/folders/myfolders/code12.txt' truncover;
  input DateTimeStamp : anydtdtm32. ASN $CWC $ TS $ Mno X Y;
  format DateTimeStamp datetime.;
  dif_y=dif(y);
  dif_x=dif(x);
run;

data x;
 merge x x(keep=dif_y dif_x rename=(dif_x=_dif_x dif_y=_dif_y) firstobs=2);
 d1=divide(dif_y,dif_x);
 d2=divide(_dif_y,_dif_x);
 if d1 gt 0 and d2 lt 0 and not missing(d2) or
   d1 lt -1 and -1 lt d2 lt 0 then do;
  if abs(dif_x) gt 2 then do;x1=x;y1=y;
  put dif_x= dif_y= _dif_x= _dif_y=;end;
 end;
run;



ods graphics/ANTIALIASMAX=5200;
proc sgplot data=x;
series x=x y=y /smoothconnect;
scatter x=x1 y=y1/ markerattrs=graphdata2(symbol=starfilled) ;
yaxis grid;
run;
Ksharp
Super User

This could be better.Your data has a little problem  , check LOG.

 

data x;
infile '/folders/myfolders/code12.txt' truncover;
  input DateTimeStamp : anydtdtm32. ASN $CWC $ TS $ Mno X Y;
  format DateTimeStamp datetime.;
  dif_y=dif(y);
  dif_x=dif(x);
run;


data x;
 merge x x(keep=dif_y dif_x rename=(dif_x=_dif_x dif_y=_dif_y) firstobs=2);
 d1=divide(dif_y,dif_x);
 d2=divide(_dif_y,_dif_x);
 if (0 lt d1 lt 0.02 and -0.02 lt d2 lt 0 ) or
  ( -1.02 lt d1 lt -1 and -1 lt d2 lt -0.98 ) then do;
  x1=x;y1=y;
  put dif_x= dif_y= _dif_x= _dif_y=;
 end;
run;



ods graphics/ANTIALIASMAX=5200;
proc sgplot data=x;
series x=x y=y /smoothconnect;
scatter x=x1 y=y1/ markerattrs=graphdata2(symbol=starfilled) ;
yaxis grid;
run;

x.png

Ksharp
Super User

This could be right.Chec coordinates in LOG.

 

data x;
infile '/folders/myfolders/code12.txt' truncover;
  input DateTimeStamp : anydtdtm32. ASN $CWC $ TS $ Mno X Y;
  format DateTimeStamp datetime.;
  dif_y=dif(y);
  dif_x=dif(x);
run;


data x;
 merge x x(keep=dif_y dif_x rename=(dif_x=_dif_x dif_y=_dif_y) firstobs=2);
 d1=divide(dif_y,dif_x);
 d2=divide(_dif_y,_dif_x);
 if (0 lt d1 lt 0.02 and -0.02 lt d2 lt 0 ) or
  ( -1.02 lt d1 lt -1 and -1 lt d2 lt -0.98 ) then do;
 if  dif_x ne 201 then do; x1=x;y1=y;
  put dif_x= dif_y= _dif_x= _dif_y=;end;
 end;
run;



ods graphics/ANTIALIASMAX=5200;
proc sgplot data=x;
series x=x y=y /smoothconnect;
scatter x=x1 y=y1/ markerattrs=graphdata2(symbol=starfilled) ;
yaxis grid;
run;

x.png

imanojkumar1
Quartz | Level 8

There are issues, sorry.... Now I understand why you were getting errors, I must clarify...

 

1. The data of X, Y where MNo. = 1 to 1260 (Date = 28SEP16:09:03:05, ASN=20) is one set of data - we have to keep it

2. The data of X, Y where MNo. = 1174 to 1243 (Date = 14Nov16, ASN=5) is another set of data - which we can ommit because it is incomlete (from 1174 to 1243 rows only)

3. The data of X, Y where MNo. = 1 to 1257 (Date = 14Nov16, ASN=20) is another set of data - we have to keep it

4. The data of X, Y where MNo. = 1 to 1282 (Date = 17Nov16:09:00:47, ASN=20) is another set of data - we have to keep it

5. The data of X, Y where MNo. = 1 to 1257 (Date = 17Nov16:18:45:14, ASN=20) is another set of data - we have to keep it

 

Now from the above comments, in the final dataset, what we need is:

 

1. Data of earliest date (28SEP16:09:03:05) from the data set - idea here is whichever is first DateTime (e.g. 28SEP16:00:00:00 will be first on that date if it is there in the dataset, otherwise whichever lowest DateTime is there will be the first as in case 28SEP16:09:03:05), take that set of Xs and Ys.

2. Whichever is latest date, we have to keep that data (e.g. point no. 5 above) - 17Nov16:18:45:14, latest date

 

In simple words, keep the data if complete (>1200 rows) and take earliest and latest dates' observations (if ASN are same for both)

Ksharp
Super User
My bad . Don't realize there are a variety of dataset in it.
This code is for 28sep2016 :



data x(where=(date='28sep2016'd));
infile '/folders/myfolders/code12.txt' truncover;
  input DateTimeStamp : anydtdtm32. ASN $CWC $ TS $ Mno X Y;
  format DateTimeStamp datetime. date date9.;
  date=datepart(datetimestamp);
  dif_y=dif(y);
  dif_x=dif(x);
run;


data want;
 merge x x(keep=dif_y dif_x rename=(dif_x=_dif_x dif_y=_dif_y) firstobs=2);
 d1=divide(dif_y,dif_x);
 d2=divide(_dif_y,_dif_x);
 if (0 lt d1 lt 0.02 and -0.02 lt d2 lt 0 ) or
  ( -1.04 lt d1 lt -1 and -1 lt d2 lt -0.96 ) or 
  (d1=0 and d2=0) then do;
  x1=x;y1=y;
  put d1= d2= dif_x= dif_y= _dif_x= _dif_y= x= y=;
 end;
run;



ods graphics/ANTIALIASMAX=5200;
proc sgplot data=want;
series x=x y=y /smoothconnect break;
scatter x=x1 y=y1/ markerattrs=graphdata2(symbol=starfilled) ;
yaxis grid;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 18 replies
  • 4210 views
  • 5 likes
  • 3 in conversation