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

Hi, I have a quarterly dataset named ab with variables DATADATE,LPERMNO,DLCQ, DLTTQ, CIK, CUSIP

 

I want to convert the quarterly dataset ab into monthly, but only covert “DLCQ DLTTQ”, and I want to keep the other variables CIK, CUSIP without conversion 

 

I can use this code,

proc expand data=ab out=abc from=qtr to=month;

   convert DLCQ DLTTQ;

   id DATADATE;

   by LPERMNO;

run;

 

The new data set abc only keeps,

DATADATE,LPERMNO ,DLCQ, DLTTQ,

 

Thanks for the response

1 ACCEPTED SOLUTION

Accepted Solutions
dw_sas
SAS Employee

Hi,

 

Based on your sample data, CUSIP and CIK are both constant within each level of your BY variable, LPERMNO.  Assuming LPERMNO and CUSIP are both numeric variables, you can obtain your desired output by using CIK as your BY variable instead of LPERMNO and adding LPERMNO and CUSIP to your CONVERT statement.  For example:

 

proc sort data=ab;
  by cik datadate;
run;

proc expand data=ab out=abcd from=qtr to=month;
  by cik;
  id datadate;
  convert dlcq dltt lpermno cusip;
run;

proc print data=abcd;
  var lpermno datadate dlcq dltt cusip cik;
run;

 

I hope this helps!

DW

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

So you want the variables CIK, CUSIP to be in the out= data set as well? But not with a monthly freq, correct?

mala6861
Calcite | Level 5
I want it in monthly frequency but without conversion, because they are identifiers
mala6861
Calcite | Level 5

Dear draycut,

 

So, yes I want the variables CIK, CUSIP to be in the out= data set as well.

 

 

DATA AB

 

LPERMNODATADATE DLCQDLTTCUSIPCIK 
111Jan-90111.15422.4622abc
111Apr-90112.35504.7622abc
111Jul-90113.65570.5622abc
111Oct-90114.55557.5622abc
113Jan-90115.95589988mkk
113Apr-90116.85652.6988mkk
113Jul-90117.45709.2988mkk
113Oct-90.5736.6988mkk

 

 

after using this code

proc expand data=ab out=abc from=qtr to=month;

   convert DLCQ DLTTQ;

   id DATADATE;

   by LPERMNO;

run;

 

I get the dataset abc 

 

LPERMNODATADATEDLCQDLTT
111Jan-90110.8795409.69
111Feb-90111.0485417.67
111Mar-90111.3675439.39
111Apr-90111.8025470.58
111May-90112.2975505.35
111Jun-90112.8015538.14
111Jul-90113.2645563.38
111Aug-90113.6415575.69
111Sep-90113.9055572.49
111Oct-90114.1395561.64
111Nov-90114.4515553.83
111Dec-90114.9095556.92
113Jan-91115.4525570.06
113Feb-91115.9375588.18
113Mar-91116.3145608.68
113Apr-91116.65630.81
113May-91116.8125652.92
113Jun-91116.9885674.06
113Jul-91117.1645693.43
113Aug-91117.385710.54
113Sep-91117.6655724.11
113Oct-91.5733.65
113Nov-91.5738.46
113Dec-91.5737.75

 

 

However, I want to keep the CUSIP and CIK as well, with out converting (not like DLCQ and DLTT), just like LPREMNO, so my data set should look like below

 

LPERMNODATADATE DLCQDLTTCUSIPCIK 
111Jan-90110.8795409.69622abc
111Feb-90111.0485417.67622abc
111Mar-90111.3675439.39

622

abc
111Apr-90111.8025470.58622abc
111May-90112.2975505.35622abc
111Jun-90112.8015538.14622abc
111Jul-90113.2645563.38622abc
111Aug-90113.6415575.69622abc
111Sep-90113.9055572.49622abc
111Oct-90114.1395561.64622abc
111Nov-90114.4515553.83622abc
111Dec-90114.9095556.92622abc
113Jan-91115.4525570.06988mkk
113Feb-91115.9375588.18988mkk
113Mar-91116.3145608.68988mkk
113Apr-91116.65630.81988mkk
113May-91116.8125652.92988mkk
113Jun-91116.9885674.06988mkk
113Jul-91117.1645693.43988mkk
113Aug-91117.385710.54988mkk
113Sep-91117.6655724.11988mkk
113Oct-91.5733.65988mkk
113Nov-91.5738.46988mkk
113Dec-91.5737.75988mkk
somebody
Lapis Lazuli | Level 10

Hi @mala6861

I run into your post which might be useful to me in the future. I have a quick question regarding your sample output. The values for DLCQ and DLTT are different between dataset abc and ab. For example, with LPERMNO = 111 and datate = Jan 90, DLCQ = 111.1 and DLTT=5422.4 in ab but they are 110.879 and 5409.69 in abc, and so on. Is there any reason for these differences? Shouldn't the values for Jan-90, Apr-90, Jul-90 ... be the same in both datasets?

dw_sas
SAS Employee

Hi @somebody,

 

Thanks for your question.  When I run the sample input data and the solution code provided, the values for Jan-90, Apr-90, Jul-90, etc.,  in the monthly output data set, abc, are the same as the original quarterly values for those dates in the input data set, ab.  Please see the full example code below for illustration.

 

data ab;
  input lpermno date: monyy5. dlcq dltt cusip cik $;
  format date date9.;
  datalines;
111 jan90 111.1 5422.4 622 abc
111 apr90 112.3 5504.7 622 abc
111 jul90 113.6 5570.5 622 abc
111 oct90 114.5 5557.5 622 abc
113 jan90 115.9 5589 988 mkk
113 apr90 116.8 5652.6 988 mkk
113 jul90 117.4 5709.2 988 mkk
113 oct90 . 5736.6 988 mkk
;

proc print data=ab;
run;

proc sort data=ab;
  by cik date;
run;

proc expand data=ab out=abcd from=qtr to=month;
  by cik;
  id date;
  convert dlcq dltt lpermno cusip;
run;

proc print data=abcd;
  var lpermno date dlcq dltt cusip cik;
run;

 

I hope this helps!

DW

dw_sas
SAS Employee

Hi,

 

Based on your sample data, CUSIP and CIK are both constant within each level of your BY variable, LPERMNO.  Assuming LPERMNO and CUSIP are both numeric variables, you can obtain your desired output by using CIK as your BY variable instead of LPERMNO and adding LPERMNO and CUSIP to your CONVERT statement.  For example:

 

proc sort data=ab;
  by cik datadate;
run;

proc expand data=ab out=abcd from=qtr to=month;
  by cik;
  id datadate;
  convert dlcq dltt lpermno cusip;
run;

proc print data=abcd;
  var lpermno datadate dlcq dltt cusip cik;
run;

 

I hope this helps!

DW

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 2293 views
  • 1 like
  • 4 in conversation