Creating a new variable in one dataset from information from a second dataset

Reply
New User
Posts: 1

Creating a new variable in one dataset from information from a second dataset

Hi all,

I am a new user of SAS, and the learning curve is steep but Im getting there slowly.

I was hoping someone could help me.

What I have is two data sets.

The first data set (work.road) has information about sections of road, these sections are defined by 4 varibales; the road name (road_no) the carriage way type, whether it be left, right or single (cway) and a start and finish point (slk_start and slk_end).

The second data set (work.crashes) has information about the location and nature of crashes, where each row is a different crash. The location information about each crash includes road_no, cway and a specific point along the road (slk).

What I wish to do is create a new variable in work.road that represents the number of crashes along each section of road (or observation/row).

So my question can be worded something along the lines of: How many observations in work.crashes have the same road_no and cway and where SLK_start le SLK le SLK_end for each observation/row in work.road?

I have done alot of reading in the SAS help pages and resources and have found things including hash and hiter that seem promising, however, as I am only a new user I don't fully understand how they work and are therefore having problems trying to impose my additional limitations and criteria on the more simple examples.

Am I on the right track?

Can someone help me write some code to perform this type of merging?

Thanks a lot in advance,

Regards,

Fritha

Super Contributor
Posts: 644

Re: Creating a new variable in one dataset from information from a second dataset

Posted in reply to FrithaArgus

Leave hash techniques aside for the time being until you are more advanced.

This question can be readily answered using Proc SQL with a left join and a count function

Richard

Ask a Question
Discussion stats
  • 1 reply
  • 122 views
  • 3 likes
  • 2 in conversation