Need assistance in a SAS Program

New Contributor
Posts: 2

Need assistance in a SAS Program

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.


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;


format id ssn11;


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;


Super User
Posts: 6,756

Re: Need assistance in a SAS Program


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.

New Contributor
Posts: 2

Re: Need assistance in a SAS Program

Posted in reply to Astounding

Thank you very for you info and advises. Smiley Happy

Ask a Question
Discussion stats
  • 2 replies
  • 1 like
  • 2 in conversation