SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
wespol
Calcite | Level 5

Hello,

I have a CSV file similar to this one:

;Red;Blue;Green;Yellow;Black
Group 1;472;124;577;242;367
Group 2;272;97;715;252;255
Group 3;246;233;121;144;209

And I would like to get a bar chart such as the following, then do a chi-squared test:

diag.png

I can't find a solution by browsing the documentation; could someone please help me?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
infile cards truncover dlm=';';
input group :$40. Red Blue Green Yellow Black;
cards4;
Group 1;472;124;577;242;367
Group 2;272;97;715;252;255
Group 3;246;233;121;144;209
;;;;

proc transpose data=have out=want;
by group;
var _numeric_;
run;

proc sgplot data=want;
vbar _name_/group=group response=col1  groupdisplay=cluster;
xaxis label=' ';
yaxis label=' ';
run;


proc freq data=want;
table _name_*group/chisq ;
weight col1;
run;

View solution in original post

4 REPLIES 4
Ksharp
Super User
data have;
infile cards truncover dlm=';';
input group :$40. Red Blue Green Yellow Black;
cards4;
Group 1;472;124;577;242;367
Group 2;272;97;715;252;255
Group 3;246;233;121;144;209
;;;;

proc transpose data=have out=want;
by group;
var _numeric_;
run;

proc sgplot data=want;
vbar _name_/group=group response=col1  groupdisplay=cluster;
xaxis label=' ';
yaxis label=' ';
run;


proc freq data=want;
table _name_*group/chisq ;
weight col1;
run;
wespol
Calcite | Level 5
Thank you for your feedback.
Is there any way to do it immediately from the CSV file?
ballardw
Super User

@wespol wrote:
Thank you for your feedback.
Is there any way to do it immediately from the CSV file?

SAS basically works with SAS data sets. So read an external file, such as CSV, into a data set and then do analysis or other actions with that data set.

 

 

Ksharp
Super User

Sure .It is easy to read CSV into SAS .

 

proc import datafile='c:\temp\have.csv' out=have dbms=csv replace;
delimiter=';';
guessingrows=max;
run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1080 views
  • 0 likes
  • 3 in conversation