Eliminating Blanks within Variables (?)

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 121
Accepted Solution

Eliminating Blanks within Variables (?)

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;

Attachment

Accepted Solutions
Solution
‎09-17-2014 02:51 PM
Super User
Posts: 11,107

Re: Eliminating Blanks within Variables (?)

In the datastep you read the data:

description =compress(description);

View solution in original post


All Replies
Solution
‎09-17-2014 02:51 PM
Super User
Posts: 11,107

Re: Eliminating Blanks within Variables (?)

In the datastep you read the data:

description =compress(description);

🔒 This topic is solved and locked.

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

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