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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 4 replies
  • 863 views
  • 0 likes
  • 3 in conversation