Help using Base SAS procedures

Please help me with a conditional merge, I attached a file.

Accepted Solution Solved
Reply
Contributor
Posts: 36
Accepted Solution

Please help me with a conditional merge, I attached a file.


I need to asign a numeric rating for each bond ( my sample size is very large). There are 4 main credit agencies  giving a letter credit rating for certain year/company ( this rating may change). I attached a table that include the numeric rating for each corresponding letter rating of each agency .

Thanks!

Attachment

Accepted Solutions
Solution
‎12-19-2012 01:41 PM
Super User
Super User
Posts: 6,495

Re: Please help me with a conditional merge, I attached a file.

Why not just merge the data with your attached table?  You will probably want to reformat the data so that you have one row per credit agency and rating letter grade pair.

data cr ;

  infile 'Credit_ratings.csv' dlm=',' dsd truncover ;

  input raten @;

  do agency = 'SPR', 'MR', 'FRR', 'DPR' ;

     input ratech $ @ ;

     if ratech ne ' ' then output ;

  end;

run;

proc sql noprint ;

  create table want as

    select a.*,b.raten

    from have a left join cr b

    on   a.agency = b.agency

     and a.ratech = b.ratech

  ;

quit;

View solution in original post


All Replies
Respected Advisor
Posts: 3,124

Re: Please help me with a conditional merge, I attached a file.

A slice of your sample data would help to promote more concrete and prompt responses.

Haikuo

Frequent Contributor
Posts: 86

Re: Please help me with a conditional merge, I attached a file.

You can Create a custom format with Proc format and apply the same in your data.

For example:

proc format;

value $rate 

            'AAA' = 1

              'AA+' = 2

            'A+'  = 3

            'BBB' = 4

;

run;

Data want;

  set have;

   format variable-name rate.;

run;

Solution
‎12-19-2012 01:41 PM
Super User
Super User
Posts: 6,495

Re: Please help me with a conditional merge, I attached a file.

Why not just merge the data with your attached table?  You will probably want to reformat the data so that you have one row per credit agency and rating letter grade pair.

data cr ;

  infile 'Credit_ratings.csv' dlm=',' dsd truncover ;

  input raten @;

  do agency = 'SPR', 'MR', 'FRR', 'DPR' ;

     input ratech $ @ ;

     if ratech ne ' ' then output ;

  end;

run;

proc sql noprint ;

  create table want as

    select a.*,b.raten

    from have a left join cr b

    on   a.agency = b.agency

     and a.ratech = b.ratech

  ;

quit;

Contributor
Posts: 36

Re: Please help me with a conditional merge, I attached a file.


Tom, Thank you very much. It works perfectly.

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 191 views
  • 3 likes
  • 4 in conversation