BookmarkSubscribeRSS Feed
SamLiya
Calcite | Level 5

Hi Everyone Smiley Happy,

I need assistance in the following code as I need to understand it and I'm not sure whether it fully correct, at the 1st place as log states ERROR in certain parts.

Thanks.

data marks;

retain key1 - key10;

array key{*} key1 - key10;

array ans{*} ans1 - ans10;

array s{*} s1 - s10;

if _n_ = 1 then do;

input @ 11 (key1 - key10) (1.);

delete; end;

else do; input id 1-10 (ans1 - ans10)(1.);

do I = 1 to 10;

if key {I} = ans{I} then S{I}=1;

else S{I} = 0; end;

row = sum(of s1-s10);

percent = 100*row/10;

drop I Key1-key10;

end;

format id ssn11;

cards;

anskey 3 4 5 6 7 8 9 5 4 2

1 2 5 7 8 9 6 4 5 1 2 1

2 3 5 4 7 8 9 6 5 7 4 1

3 8 5 2 3 6 4 1 2 5 4 7

;

proc sort; by id;

proc print; id id;

var row percent;

proc chart;

vbar percent/midpoints = 50 to 100 by 5;

proc freq;

tables ans1-ans10;

run;

2 REPLIES 2
Astounding
PROC Star

Sam,

I'm afraid you have a lot of work ahead of you, to be able to understand this program.  I can tell you that without even looking at the program itself, just based on your first sentence.  You should be 100% sure that the program is incorrect, if you are receiving ERROR messages.  And you should know that it would be helpful for us to see what the error messages are, to help fix the program.  You can learn what you need, but you have some work ahead of you to learn it.

That being said, a couple of things stand out.  In the FORMAT statement, there should be a "dot" at the end:

format id ssn11.;

The "dot" lets SAS distinguish that ssn11. is the name of a format, not the name of a variable.

The major issue in this program is that the INPUT statements do not match the data following your CARDS statement.  The INPUT statements are the instructions on what data to read in, and where to find it.  You'll need to learn the meaning of every piece of every INPUT statement in the program, and make sure it matches the data you are trying to read.  (It is possible that you just typed in a few lines of data to illustrate, and that the "real" data has a different structure ... it's hard to tell from what you posted.)

With the right structure to the data, this program is very close to working.  But understanding why that is so will take some work.

Good luck.

SamLiya
Calcite | Level 5

Thank you very for you info and advises. Smiley Happy

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!

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
  • 2 replies
  • 445 views
  • 1 like
  • 2 in conversation