Learning SAS? Welcome to the exclusive online community for all SAS learners.

New at this and have been stuck for 10 days.. Help please.

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

New at this and have been stuck for 10 days.. Help please.

Hello all,

I am completely stuck on an assignment and have tried everything and cannnot move forward.

please see my issues.

I have put my questions inside the code.

PlEAAAASSSE HELLLP.

Thank you

/* Generated Code (IMPORT) */
/* Source File:2012_16_ChathamPed.csv */
 /* Source Path: /home/cwacta0/my_courses/Week2/ACCIDENTS */

PROC IMPORT DATAFILE ='/home/cwacta0/my_courses/Week2/ACCIDENTS/2012_16_ChathamPed.csv' OUT = imported REPLACE;GETNAMES=YES; GUESSINGROWS=32767;
RUN;

PROC IMPORT DATAFILE ='/home/cwacta0/my_courses/Week2/ACCIDENTS/2012_16_Chatham_Pedalcycle.csv' OUT = imported REPLACE; GETNAMES=YES; GUESSINGROWS=32767;
RUN;

proc contents data=work.imported; run;

libname mydata"/courses/d1406ae5ba27fe300" access=readonly;
run;

/* sorting data by route*/

PROC SORT; by LocationOfimpact;

LABEL Route="STREET NAME"
	  Fatalities="FATALITIES"
	  Injuries="INJURIES"
	  SeriousInjuries="SERIOUS INJURIES"
	  LocationOfimpact="LOCATION OF IMPACT"
	  MannerOfCollision="MANNER OF COLLISION"
	  U1Factors="PRIMARY CAUSES OF ACCIDENT"
	  U1TrafficControl="TRAFFIC CONTROL SIGNS AT THE LOCATION"
	  U2Factors="SECONDARY CAUSES OF ACCIDENT"
	  U2TrafficControl="OTHER TRAFFIC CONTROL SIGNS AT THE LOCATION"
	  Light="TYPE OF LIGHTHING AT THE TIME OF THE ACCIDENT"
	  DriverAge1="AGE OF THE DRIVER"
	  DriverAge2="AGE OF THE CYCLIST"; 

 
/* Here I was unable to extract the  drivers age 25 or less and te drivers who disregarded stop sign. here is how I coded it;
IF DriverAge1 LE 25;
IF U1Factors="Failed to Yield" OR U1Factors= "Disregard Stop Sign";
Run;
 
 Also, I want to remove the Missing DATA under the results. But in the data, those are just a blank cell. How do I tell SAS to disregard a blank cell and not add it to the result?
 Here is what I did and it does not work...
 
 if U1Factors="BLANK" Then U1Factors=".";
 Please help me figre this out...Tks*/

proc freq; tables Route Fatalities Injuries SeriousInjuries LocationOfimpact MannerOfCollision U1Factors U1TrafficControl U2Factors U2TrafficControl light DriverAge1 DriverAge2 ; 
RUN;


Accepted Solutions
Solution
‎07-18-2017 08:08 PM
New Contributor
Posts: 3

Re: New at this and have been stuck for 10 days.. Help please.


All Replies
PROC Star
Posts: 7,489

Re: New at this and have been stuck for 10 days.. Help please.

just before your label statement you need to begin a data step.

 

Art, CEO, AnalystFinder.com

 

Super User
Posts: 11,343

Re: New at this and have been stuck for 10 days.. Help please.

Second one first. Instead of

if U1Factors="BLANK" Then U1Factors=".";

Try

 

if U1Factors="BLANK" Then call missing(U1Factors);

Since your U1Factors variable is a character then assigning a . means you will see a period. The 'period' used for missing is actual a special display that SAS uses and could be any single character contolled by the Options missing='.'; (default)

 

The special function Call Missing() will set the correct missing value for either character or numeric variables AND you can have a whole list of variables of mixed types if desired.

 

It is very likely that you hare having some issues because of your import statements:

PROC IMPORT DATAFILE ='/home/cwacta0/my_courses/Week2/ACCIDENTS/2012_16_ChathamPed.csv' OUT = imported REPLACE;GETNAMES=YES; GUESSINGROWS=32767;
RUN;

PROC IMPORT DATAFILE ='/home/cwacta0/my_courses/Week2/ACCIDENTS/2012_16_Chatham_Pedalcycle.csv' OUT = imported REPLACE; GETNAMES=YES; GUESSINGROWS=32767;
RUN;

The second import overwrites the first data set because they both have the same name "Imported". So your non-pedalcycle data no longer exists.

 

I strongly recommend learning to specify the data set used for every procedure. While SAS will use the last created that may not be the one you intend if you return to previous code to make a change.

 

You code actually shows nothing that has a chance of extracting data. it would either start with a DATA statement creating a data set and referencing your existing data with a SET statement or a different approach using Proc Sql:

 

Something like:

Data want;

   set imported;

   IF DriverAge1 LE 25 And U1Factors in ("Failed to Yield",  "Disregard Stop Sign");

run;

 

You can also subset data using a where data set option:

proc print data=imported (where =(DriverAge1 LE 25 And U1Factors in ("Failed to Yield",  "Disregard Stop Sign") ));

run;

 

but you cannot use data step IF statements in other procedures  such as yours appearing in Proc Sort. There would have been all sorts of errors if attempted.

New Contributor
Posts: 3

Re: New at this and have been stuck for 10 days.. Help please.

THANK You SOOO much.

Your answer was such a learning moment.

Thank you again.

I was able to:

Extract the Driver age and now I can even do the same with the time of the day.

THANK YOU SO MUCH.

 

Two things I was unsuccessful doing are:

1. Removing the Missing DATA from the botom of the result table... In my Original data, The missing Data are just a cell with nothing in it. Then SAS show that as a DOT [.] in the OUTPUT DATA (see attached) So i assumed I will call it BLANK...

I tried what you suggested and got an error.

 

2. Can I see both my imported Data? how should I name the second data so it doenot overwrite the firts?

 

Thank you so much. 

Xtine

Super User
Posts: 19,858

Re: New at this and have been stuck for 10 days.. Help please.

Some resources you may find useful:

support.sas.com/training/tutorial

https://stats.idre.ucla.edu/sas/modules/

 

Another great way to learn, use the point and click interface and SAS Studio and examine the source code. Studio code is easier to understand compared to SAS EG but it also has a point and click interface. 

 


Xtine wrote:

Hello all,

I am completely stuck on an assignment and have tried everything and cannnot move forward.

please see my issues.

I have put my questions inside the code.

PlEAAAASSSE HELLLP.

Thank you

/* Generated Code (IMPORT) */
/* Source File:2012_16_ChathamPed.csv */
 /* Source Path: /home/cwacta0/my_courses/Week2/ACCIDENTS */

PROC IMPORT DATAFILE ='/home/cwacta0/my_courses/Week2/ACCIDENTS/2012_16_ChathamPed.csv' OUT = imported REPLACE;GETNAMES=YES; GUESSINGROWS=32767;
RUN;

PROC IMPORT DATAFILE ='/home/cwacta0/my_courses/Week2/ACCIDENTS/2012_16_Chatham_Pedalcycle.csv' OUT = imported REPLACE; GETNAMES=YES; GUESSINGROWS=32767;
RUN;

proc contents data=work.imported; run;

libname mydata"/courses/d1406ae5ba27fe300" access=readonly;
run;

/* sorting data by route*/

PROC SORT; by LocationOfimpact;

LABEL Route="STREET NAME"
	  Fatalities="FATALITIES"
	  Injuries="INJURIES"
	  SeriousInjuries="SERIOUS INJURIES"
	  LocationOfimpact="LOCATION OF IMPACT"
	  MannerOfCollision="MANNER OF COLLISION"
	  U1Factors="PRIMARY CAUSES OF ACCIDENT"
	  U1TrafficControl="TRAFFIC CONTROL SIGNS AT THE LOCATION"
	  U2Factors="SECONDARY CAUSES OF ACCIDENT"
	  U2TrafficControl="OTHER TRAFFIC CONTROL SIGNS AT THE LOCATION"
	  Light="TYPE OF LIGHTHING AT THE TIME OF THE ACCIDENT"
	  DriverAge1="AGE OF THE DRIVER"
	  DriverAge2="AGE OF THE CYCLIST"; 

 
/* Here I was unable to extract the  drivers age 25 or less and te drivers who disregarded stop sign. here is how I coded it;
IF DriverAge1 LE 25;
IF U1Factors="Failed to Yield" OR U1Factors= "Disregard Stop Sign";
Run;
 
 Also, I want to remove the Missing DATA under the results. But in the data, those are just a blank cell. How do I tell SAS to disregard a blank cell and not add it to the result?
 Here is what I did and it does not work...
 
 if U1Factors="BLANK" Then U1Factors=".";
 Please help me figre this out...Tks*/

proc freq; tables Route Fatalities Injuries SeriousInjuries LocationOfimpact MannerOfCollision U1Factors U1TrafficControl U2Factors U2TrafficControl light DriverAge1 DriverAge2 ; 
RUN;


 

Solution
‎07-18-2017 08:08 PM
New Contributor
Posts: 3

Re: New at this and have been stuck for 10 days.. Help please.

Thank you Reeza

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 903 views
  • 9 likes
  • 4 in conversation