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

I am supposed to do on this project and I have done in this way-

 

proc format;
value learningtypef 1 = 'elementary';
2 = 'middle';
3 = 'high';
data project2;
input y1-y6;

if 1 <= _n_ <= 6 then district = 'Hillsborough';
else if 7 <= _n_ <= 12 then district = 'Pinellas';
else if 13 <= _n_ <= 18 then district = 'Srasota';
else district = 'Polk';

if _n_ in ( 1, 2, 7, 8, 13, 14, 19, 20 ) then race = 'B';
else if _n_ in ( 3, 4, 9, 10, 15, 16, 21, 22 ) then race = 'W';
else race = 'O';

if _n_ in (1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, ) then gender = 'Male';
else gender = 'Female';

array project2 (6) y1-y6;
do i = 1 to 6;
if i > 3 then learntype = 'active';
else learntype = 'slow';
if i in (1,4) then level = 1;
else if i in (2,5 ) then level = 2;
else level = 3;

absentees = project2 (i);
format learningtpe learningtypef.;
Output;
end;
drop i y1-y6;

Datalines;

100 300 1600 750 250 700
150 1150 2350 450 550 850
3350 850 1800 750 600 150
1250 350 700 400 1650 700
1650 700 1150 850 250 1100
200 1600 3700 450 600 750
3800 650 1750 700 550 250
1050 400 650 350 2200 1050
1550 750 1100 900 600 1250
250 1650 2700 450 650 450
2800 1150 1550 650 800 300
600 450 1150 450 2050 1100
350 350 1650 650 200 750
100 950 1350 500 600 900
1700 550 1550 850 750 50
1200 300 850 200 1600 750
1600 3700 10 400 350 2000
335 1750 1550 2100 700 100
480 650 550 650 1600 800
220 1100 950 1600 650 50
1640 2700 500 450 400 1450
1185 1550 1900 2150 750 50
100 300 1600 750 250 700
150 1150 2350 450 550 850
;
run;
proc print data = project2;
run;

 

 

But the program is not running.I am a new learner,so I can't understand what 's the wrong and how to solve this.Please,suggest me in solving this.How I can have the number of absentees from the data file?

 

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You are working waaay toooo hard.

proc format;
value learningtypef 
  1 = 'elementary'
  2 = 'middle'
  3 = 'high'
;
run;

data project2;
length district $20 race $1 gender $6 learntype $6 level absentees 8 ;
format level learningtypef. ;
do district = 'Hillsborough','Pinellas','Srasota','Polk';
  do race = 'B', 'W', 'O';
     do gender = 'Male','Female';
       do learntype='slow','active';
         do level=1 to 3 ;
           input absentees @;
           output;
         end;
       end;
       input;
     end;
  end;
end;
datalines;
100 300 1600 750 250 700
150 1150 2350 450 550 850
3350 850 1800 750 600 150
1250 350 700 400 1650 700
1650 700 1150 850 250 1100
200 1600 3700 450 600 750
3800 650 1750 700 550 250
1050 400 650 350 2200 1050
1550 750 1100 900 600 1250
250 1650 2700 450 650 450
2800 1150 1550 650 800 300
600 450 1150 450 2050 1100
350 350 1650 650 200 750
100 950 1350 500 600 900
1700 550 1550 850 750 50
1200 300 850 200 1600 750
1600 3700 10 400 350 2000
335 1750 1550 2100 700 100
480 650 550 650 1600 800
220 1100 950 1600 650 50
1640 2700 500 450 400 1450
1185 1550 1900 2150 750 50
100 300 1600 750 250 700
150 1150 2350 450 550 850
;
run;
proc print data = project2;
run;
 

View solution in original post

9 REPLIES 9
PGStats
Opal | Level 21

There are many typos in your program. Look at the SAS log, fix the first error mentionned, and resubmit the program. Do this repeatedly until you get no suspicious messages. For starters, you shouldn't have semicolons after 1 = 'elementary' and 2 = 'middle'. That will clear the first error. There are others, none of which is difficult to fix.

PG
docsaurmi
Calcite | Level 5

Thanks for your instant response

I have followed your command for the first error and again do run the program.But the Log shows the following-

 

ERROR 22-322: Syntax error, expecting one of the following: a quoted string,
a numeric constant, a datetime constant, a missing value, iterator, (.

ERROR 76-322: Syntax error, statement will be ignored.

 NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.PROJECT2 may be incomplete. When this step was stopped there were
0 observations and 7 variables.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

As has been mentioned by PG Stats you have a fair few issues in your code.  I have corrected these below.  However before I would like to check what you are aiming to do as it does seem to contain various items I would not recommend.  Firstly all your calculations seem to be based off _n_ which is an automatic variable which indicates row number.  That to me is very dangerous, if another row is added, or its sorted differently then the output is incorrect.  I would suggest that the data needs to indicate the data elements, not some ad-hoc position or order.  Secondly, at no point in your code do you appear to do anything with the data you read in, so what is the point of this?  As simple:

data want;

  do i=1 to 6;

    ...;

    output;

  end;

run;

Would do exactly the same thing without any need for the datalines?

 

proc format;
  value learningtypef 
    1 = 'elementary'
    2 = 'middle'
    3 = 'high';
run;
data project2;
  input y1-y6;
  if 1 <= _n_ <= 6 then district = 'Hillsborough';
  else if 7 <= _n_ <= 12 then district = 'Pinellas';
  else if 13 <= _n_ <= 18 then district = 'Srasota';
  else district = 'Polk';
  if _n_ in ( 1, 2, 7, 8, 13, 14, 19, 20 ) then race = 'B';
  else if _n_ in ( 3, 4, 9, 10, 15, 16, 21, 22 ) then race = 'W';
  else race = 'O';
  if _n_ in (1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25) then gender = 'Male';
  else gender = 'Female';
  array project2 (6) y1-y6;
  do i = 1 to 6;
    if i > 3 then learningtype = 'active';
    else learningtype = 'slow';
    if i in (1,4) then level = 1;
    else if i in (2,5 ) then level = 2;
    else level = 3;
    absentees = project2 (i);
    format learningtype learningtypef.;
    Output;
  end;
  drop i y1-y6;
Datalines;
100 300 1600 750 250 700
150 1150 2350 450 550 850
3350 850 1800 750 600 150
1250 350 700 400 1650 700
1650 700 1150 850 250 1100
200 1600 3700 450 600 750
3800 650 1750 700 550 250
1050 400 650 350 2200 1050
1550 750 1100 900 600 1250
250 1650 2700 450 650 450
2800 1150 1550 650 800 300
600 450 1150 450 2050 1100
350 350 1650 650 200 750
100 950 1350 500 600 900
1700 550 1550 850 750 50
1200 300 850 200 1600 750
1600 3700 10 400 350 2000
335 1750 1550 2100 700 100
480 650 550 650 1600 800
220 1100 950 1600 650 50
1640 2700 500 450 400 1450
1185 1550 1900 2150 750 50
100 300 1600 750 250 700
150 1150 2350 450 550 850
;
run;
docsaurmi
Calcite | Level 5

RW9,

 Thanks for your kind help. I am a new sas learner. I have followed your correction but still now  the log window showing me the following-

 

ERROR 48-59: The format $LEARNINGTYPEF was not found or could not be loaded.

 

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.PROJECT2 may be incomplete. When this step was stopped there were 0
observations and 6 variables.
WARNING: Data set WORK.PROJECT2 was not replaced because this step was stopped.

 

 Don'tunderstand yet what's the wrong with this.

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

You are trying to apply a numeric format learningtype, to a character variable.  Take the format xyz learningtype.; statement out when you are dealing with the character variable reg.  Or create a character format as well.

ndp
Quartz | Level 8 ndp
Quartz | Level 8

1) Remove ';' from format values 1 and 2

2) remove last ',' before ')' from below:

if _n_ in (1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, ) then gender = 'Male';

3) I believe you want to use format for variable level instead of learningtype

 

Tom
Super User Tom
Super User

You are working waaay toooo hard.

proc format;
value learningtypef 
  1 = 'elementary'
  2 = 'middle'
  3 = 'high'
;
run;

data project2;
length district $20 race $1 gender $6 learntype $6 level absentees 8 ;
format level learningtypef. ;
do district = 'Hillsborough','Pinellas','Srasota','Polk';
  do race = 'B', 'W', 'O';
     do gender = 'Male','Female';
       do learntype='slow','active';
         do level=1 to 3 ;
           input absentees @;
           output;
         end;
       end;
       input;
     end;
  end;
end;
datalines;
100 300 1600 750 250 700
150 1150 2350 450 550 850
3350 850 1800 750 600 150
1250 350 700 400 1650 700
1650 700 1150 850 250 1100
200 1600 3700 450 600 750
3800 650 1750 700 550 250
1050 400 650 350 2200 1050
1550 750 1100 900 600 1250
250 1650 2700 450 650 450
2800 1150 1550 650 800 300
600 450 1150 450 2050 1100
350 350 1650 650 200 750
100 950 1350 500 600 900
1700 550 1550 850 750 50
1200 300 850 200 1600 750
1600 3700 10 400 350 2000
335 1750 1550 2100 700 100
480 650 550 650 1600 800
220 1100 950 1600 650 50
1640 2700 500 450 400 1450
1185 1550 1900 2150 750 50
100 300 1600 750 250 700
150 1150 2350 450 550 850
;
run;
proc print data = project2;
run;
 
docsaurmi
Calcite | Level 5

Thank you so much to all of your suggestion. Now, my program is running.Hope I am going to learn a lot from this forum.

AnnaBrown
Community Manager

I'm glad to hear you resolved the issue, docsaurmi. Can you mark which reply worked for you by clicking "Accept as solution"? I hope to "see" you here in the community again soon! 

 

Anna

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 9 replies
  • 2877 views
  • 0 likes
  • 6 in conversation