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

I have the following code which I apply to the attached .csv file; my question/problem pertains to the variable Description found in the NCDebt2 dataset. Is there a way to eliminate the blanks found within (ie not leading and trailing blanks) the values of the Description variable?

data WORK.NCDebt;
     infile '/fmacdata/utility/fin/KBenchmarks/SAS Data/Debt.csv' dsd lrecl=40000 firstobs=3;
informat InstrumentName $15.;
informat PriceToPublic 10.8;
informat Cusip $15.;
informat CouponDates mmddyy10.;
informat ValuationDate yymmdd.;
informat AccruedDayCount $10.;
informat FullPrice 10.8;
informat InterestFrequency 5.;
informat Notional 12.;
informat MaturityDate mmddyy10.;
informat ID $10.;
informat FaceValues 8.;
informat PaymentDayCount $10.;
informat FlatPrice 10.8;
informat Description $80.;
informat Comments $30.;
informat MarketCleanPrice 10.8;
informat SettlementDate yymmdd.;
informat Name $20.;
informat Category $40.;
informat PaymentDates mmddyy10.;
informat AnnualCouponRates 6.4;
informat OriginationDate mmddyy10.;
informat FirstCpnDt mmddyy10.;
informat Issuer $30.;
informat CouponType $30.;
format PriceToPublic FullPrice 10.8
       CouponDates MaturityDate ValuationDate PaymentDates OriginationDate
       SettlementDate FirstCpnDt yymmddn8.;
input InstrumentName $ PriceToPublic Cusip $ CouponDates ValuationDate
      AccruedDayCount $ FullPrice InterestFrequency Notional MaturityDate
      ID $ FaceValues PaymentDayCount $ FlatPrice Description $ Comments $
      MarketCleanPrice  SettlementDate Name $ Category $ PaymentDates 
      AnnualCouponRates OriginationDate FirstCpnDt Issuer $ CouponType $;
ID=Cusip;
Name=Cusip;
Y=round(((MaturityDate-OriginationDate)/360),0.1);
X=MaturityDate;
if index(Issuer,'TREASURY') then do;
   if CouponType='FIXED' then Category='TreasuryDebt.NonCallable.FixedRate';
   else if CouponType ne 'FIXED' then Category='TreasuryDebt.NonCallable.ZeroCoupon';
end;
else do;
   if CouponType='FIXED' then Category='AgencyDebt.NonCallable.FixedRate';
   else if CouponType ne 'FIXED' then Category='AgencyDebt.NonCallable.ZeroCoupon';
end;
run;


data NCDebt2;
  retain InstrumentName PriceToPublic Cusip CouponDates ValuationDate
         AccruedDayCount DiscountSource FullPrice UnderWriterDelivery
         InterestFrequency Notional MaturityDate ID FaceValues
         PaymentDayCount CouponAdjusting FlatPrice Description Comments
         MarketCleanPrice BusinessDayAdjust CouponEntry SettlementDate Name Category
         PaymentDates AnnualCouponRates UnderwriterDiscount DisableLegacyMeasures
         OriginationDate OAS FirstCpnDt;
         DiscountSource='OIS';
         UnderWriterDelivery=-1;
         CouponAdjusting='false';
         BusinessDayAdjust='Following';
         CouponEntry='Manual';
  UnderwriterDiscount=0.0;
         DisableLegacyMeasures='false';
         OAS=0.0;
         format UnderwriterDiscount 3.1;
         set NCDebt;
         Y=strip(Y);
         AnnualCouponRates=strip(AnnualCouponRates);
         Z=put(X,mmddyy10.);
         if index(Issuer,'TREASURY') then
           Description='USTreas  '||AnnualCouponRates||'% '||Y||' YR '||Z;
         else if index(Issuer,'VALLEY') then
           Description='TVA  '||AnnualCouponRates||'% '||Y||' YR '||Z;
         else if index(Issuer,'FANNIE') then
           Description='FNMA  '||AnnualCouponRates||'% '||Y||' YR '||Z;
         AnnualCouponRates=AnnualCouponRates/100;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

In the datastep you read the data:

description =compress(description);

View solution in original post

1 REPLY 1
ballardw
Super User

In the datastep you read the data:

description =compress(description);

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 607 views
  • 0 likes
  • 2 in conversation