BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
matt23
Quartz | Level 8

I am trying to do a scatterplot with two groups (5 PM and 4 AM) but it also shows overall over the groups making it messy.

I have this:

data dataname2;
   set dataname;
   if Hour in (17) then grouphour='5 P.M.';
   if Hour in (4) then grouphour='4 P.M.';
run;

proc sgplot data=dataname2; 
where Month in (6,7,8);
where also Weekday in (1,2,3,4,5);
scatter x=Xvar y=Yvar / group=grouphour;
reg x=Xvar y=Yvar;

title '5 P.M. vs 4 A.M. (summer)';
run;

Also, is there an easier way to do this without making new dataset?

 

like group1 = Hour(17) group2 = Hour(4) or something like that?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Exclude/Include them in the WHERE statement. 

 

proc sgplot data=dataname; 

where Month in (6,7,8)
           and Weekday in (1,2,3,4,5) 
           and hour in (4, 17);

scatter x=Xvar y=Yvar / group=hour;
reg x=Xvar y=Yvar;

title '5 P.M. vs 4 A.M. (summer)';

run 

 

View solution in original post

3 REPLIES 3
Reeza
Super User

Do you want the rest of the hours included and only those two hours highlighted? If so, a temp data set is the easiest method.

Or just those two hours - this is easy adding a condition to your WHERE statement for HOUR.

 


@matt23 wrote:

I am trying to do a scatterplot with two groups (5 PM and 4 AM) but it also shows overall over the groups making it messy.

I have this:

data dataname2;
   set dataname;
   if Hour in (17) then grouphour='5 P.M.';
   if Hour in (4) then grouphour='4 P.M.';
run;

proc sgplot data=dataname2; 
where Month in (6,7,8);
where also Weekday in (1,2,3,4,5);
scatter x=Xvar y=Yvar / group=grouphour;
reg x=Xvar y=Yvar;

title '5 P.M. vs 4 A.M. (summer)';
run;

Also, is there an easier way to do this without making new dataset?

 

like group1 = Hour(17) group2 = Hour(4) or something like that?


 

matt23
Quartz | Level 8

No, I only want the two hours but on top of them I get both of them combined. I don't want the combined one and I don't know why it even shows.

Reeza
Super User

Exclude/Include them in the WHERE statement. 

 

proc sgplot data=dataname; 

where Month in (6,7,8)
           and Weekday in (1,2,3,4,5) 
           and hour in (4, 17);

scatter x=Xvar y=Yvar / group=hour;
reg x=Xvar y=Yvar;

title '5 P.M. vs 4 A.M. (summer)';

run 

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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