BookmarkSubscribeRSS Feed
tahoora
Calcite | Level 5

this code have 2 important error forst I should omit proc secound I should move the datalines end semilocon to net line.

perfect I dontt havve ANY MORE ERROR. 

this my sample project I have one dataline that I waant to save as sas dataset .

I use Ubuntu. and I have 3 different error all related to my voter dataset. 

I fixed my error but I get new error related to 

libname voter "/folders/myfolders/chapter5";
proc format ;
value age 0<-30='0–30'
30<-50=' 31–50'
50<-70='51–70'
70<-high='71+';
value $partys
'D'= Democrat
'R' =Republican;
value $likely
'1'='Generally Disagree'
'2'='No Opinion'
'3'='Generally Agree';
data voter.test1 ;
input Age Party : $1. (Ques1-Ques4)($1. + 1);
label Ques1='The president is doing a good job'
Ques2='Congress is doing a good job'
Ques3='Taxes are too high'
Ques4='Government should cut spending';
format Age age. Party $partys. Ques1-Ques4 $likely.;
datalines;
23 D 1 1 2 2
45 R 5 5 4 1
67 D 2 4 3 3
39 R 4 4 4 4
19 D 2 1 2 1
75 D 3 3 2 3
57 R 4 3 4 4
;

proc print data=voter.test1;
where Ques1<'4' and Ques2<'2' and Ques3<'4' and Ques4<'4';
run;
proc freq data=voter.test1;
by Ques1-Ques4;
format Ques1-Ques4 $likely.;
where Ques1<'4' and Ques2<'2' and Ques3<'4' and Ques4<'4';
run;

 

 

this is my log

 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         libname voter "&/folders/myfolders/chapter5";
 NOTE: Library VOTER does not exist.
 74         proc format ;
 75         value age 0<-30='0–30'
 76         30<-50=' 31–50'
 77         50<-70='51–70'
 78         70<-high='71+';
 NOTE: Format AGE is already on the library WORK.FORMATS.
 NOTE: Format AGE has been output.
 79         value $partys
 80         'D'= Democrat
 81          'R' =Republican;
 NOTE: Format $PARTYS is already on the library WORK.FORMATS.
 NOTE: Format $PARTYS has been output.
 82         value $likely
 83         '1'='Generally Disagree'
 84         '2'='No Opinion'
 85         '3'='Generally Agree';
 NOTE: Format $LIKELY is already on the library WORK.FORMATS.
 NOTE: Format $LIKELY has been output.
 86         
 87         
 
 NOTE: PROCEDURE FORMAT used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 88         proc data=voter.test1 ;
 ERROR: Procedure DATA not found.
 89         input Age Party : $1. (Ques1-Ques4)($1. + 1);
 90         label Ques1='The president is doing a good job'
 91         Ques2='Congress is doing a good job'
 92         Ques3='Taxes are too high'
 93         Ques4='Government should cut spending';
 94         format Age age. Party  $partys. Ques1-Ques4 $likely.;
 95         
 96         
 97         
 98         datalines;
 99         23 D 1 1 2 2
 100        45 R 5 5 4 1
 101        67 D 2 4 3 3
 102        39 R 4 4 4 4
 103        19 D 2 1 2 1
 104        75 D 3 3 2 3
 105        57 R 4 3 4 4
 106        ;
 
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE DATA used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 
 107        proc print data=voter.test1;
 ERROR: File VOTER.TEST1.DATA does not exist.
 108        where Ques1<'4' and Ques2<'2' and Ques3<'4' and Ques4<'4';
 WARNING: No data sets qualify for WHERE processing.
 109        run;
 
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 
 110        proc freq data=voter.test1;
 ERROR: File VOTER.TEST1.DATA does not exist.
 111        by Ques1-Ques4;
 112        format Ques1-Ques4 $likely.;
 113        where Ques1<'4' and Ques2<'2' and Ques3<'4' and Ques4<'4';
 WARNING: No data sets qualify for WHERE processing.
 114        run;
 
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE FREQ used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 115        
 116        OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 129        

 

5 REPLIES 5
Kurt_Bremser
Super User
libname voter "&/folders/myfolders/chapter5";

points  to a badly written physical library name (the & doesn't belong there).

And here

proc data=voter.test1 ;

you probably want a data statement:

data voter.test1;
andreas_lds
Jade | Level 19

SAS has no procedure named "data". Changing

 

proc data=voter.test1 ;

 

to

 

data voter.test1;

should solve the error.

 

 

EDIT: Thought to long about recommending to add "run;" after each step, but decided skip that for now.

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Step 1 should always be write code in a way which is best suited to reading the code.  I have corrected below:

proc format;
value age
0<-30='0–30'
30<-50=' 31–50'
50<-70='51–70'
70<-high='71+';
value $partys
'D'= Democrat
'R' =Republican;
value likely
1='Generally Disagree'
2='No Opinion'
3='Generally Agree';
run;

data test1;
input age party $ ques1 ques2 ques3 ques4;
label ques1='The president is doing a good job'
ques2='Congress is doing a good job'
ques3='Taxes are too high'
ques4='Government should cut spending';
format age age. party $partys. ques1-ques4 likely.;
datalines;
23 D 1 1 2 2
45 R 5 5 4 1
67 D 2 4 3 3
39 R 4 4 4 4
19 D 2 1 2 1
75 D 3 3 2 3
57 R 4 3 4 4
;
run;

proc print data=test1;
where Ques1 < 4 and Ques2 < 2 and Ques3 < 4 and Ques4 < 4;
run;

proc freq data=test1;
by ques1-ques4;
where ques1 < 4 and ques2 < 2 and ques3 < 4 and ques4 < 4;
run;

There are several things.  First the proc data as mentioned before is incorrect, a datastep is started by "data " then the libname and dataset name.

Secondly you are dealing with numeric question responses, there is no value in storing these as text, so read them as numeric, apply a numeric format to them, and drop the quotes around where clauses.

tahoora
Calcite | Level 5

char format accept numeric format value!

RW9
Diamond | Level 26 RW9
Diamond | Level 26

You don't understand what is happening though.  This:

where Ques1<'4'

Is not saying is the value in ques1 less than 4, it is saying is the character number from the ascii table found before the character number for '4' in the ascii table.  Whilst in this instance where you have that data it works, as 1,2,3 are in the ascii table before the character 4, if your data has slight differences, ' 1', '.1' etc. which numerics can have, then your code will not work as you intend.

Therefore, if you are dealing with numeric data, use a numeric variable type.  It also saves you typing lots of quotes.  The format will still work exactly as before, but behind the scenes you are working with numeric data so x < 4 is far more robust.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 5 replies
  • 2156 views
  • 1 like
  • 4 in conversation