Help using Base SAS procedures

help with the code

Reply
Frequent Contributor
Posts: 96

help with the code

Hello Everyone,

I have the following data with me which has company_name, url, and filing_date:

1AMERICAN MEDICAL HOLDINGS INCedgar/data/861439/0000912057-94-000263.txt29NOV1993
2ELIZABETHTOWN GAS COedgar/data/32377/0000032377-94-000001.txt13DEC1993
3DISNEY WALT COedgar/data/29082/0000950131-94-000021.txt22DEC1993
4INTERNATIONAL GAME TECHNOLOGYedgar/data/353944/0000353944-94-000005.txt23DEC1993
5FRANKLIN RESOURCES INCedgar/data/38777/0000038777-94-000002.txt06JAN1994
6ADC TELECOMMUNICATIONS INCedgar/data/61478/0000912057-94-000081.txt12JAN1994
7MORTGAGE & REALTY TRUSTedgar/data/79259/0000912057-94-000090.txt13JAN1994
8SUMMIT SECURITIES INC /ID/edgar/data/868016/0000868016-94-000002.txt13JAN1994
9DUPLEX PRODUCTS INCedgar/data/30547/0000950124-94-000148.txt18JAN1994
10BOWNE & CO INCedgar/data/13610/0000950123-94-000205.txt26JAN1994


Based on this information, I want to do two things:

First I want to create a new variable, YEAR, which takes the same year from the filing_date if the filing month is period after March. In other words if the filing_date is 29 MArch 1993 then year is 1992. If filing_date is 12Oct1993 then YEAR =1993.

Second, I need to change the name of the url to company_name.year.txt. For instance, I want the name of the url for Disney walt co to be disneywalt.1993.txt

I would highly appreciate if anyone can provide me with the code.

Super User
Posts: 17,907

Re: help with the code

Try using some SAS functions - qtr gets the quarter from SAS date

and compress - removes spaces

and catx - concatenates strings together.

if qtr(file_date)=1 then year=year(file_date)-1; else year=year(file_date);

url_new=catx(".", compress(company_name), year, ".txt");

Super Contributor
Posts: 1,636

Re: help with the code

data have(drop=n);

infile cards delimiter=' ';

informat date date9.;

format date mmddyy10.;

input n name :&$30. url &:$50. date;

cards;

1 AMERICAN MEDICAL HOLDINGS INC edgar/data/861439/0000912057-94-000263.txt 29NOV1993

2 ELIZABETHTOWN GAS CO edgar/data/32377/0000032377-94-000001.txt 13DEC1993

3 DISNEY WALT CO edgar/data/29082/0000950131-94-000021.txt 22DEC1993

4 INTERNATIONAL GAME TECHNOLOGY edgar/data/353944/0000353944-94-000005.txt 23DEC1993

5 FRANKLIN RESOURCES INC edgar/data/38777/0000038777-94-000002.txt 06JAN1994

6 ADC TELECOMMUNICATIONS INC edgar/data/61478/0000912057-94-000081.txt 12JAN1994

7 MORTGAGE & REALTY TRUST edgar/data/79259/0000912057-94-000090.txt 13JAN1994

8 SUMMIT SECURITIES INC /ID/  edgar/data/868016/0000868016-94-000002.txt 13JAN1994

9 DUPLEX PRODUCTS INC edgar/data/30547/0000950124-94-000148.txt 18JAN1994

10 BOWNE & CO INC edgar/data/13610/0000950123-94-000205.txt 26JAN1994

;

data want;

set have;

year=ifn(month(date)>3,year(date),year(date)-1);

url=compress(catx('.',name,year,'txt'));

run;

options nocenter ls=130;

proc print;run;

Obs          date    name                             url                                     year

  1    11/29/1993    AMERICAN MEDICAL HOLDINGS INC    AMERICANMEDICALHOLDINGSINC.1993.txt     1993

  2    12/13/1993    ELIZABETHTOWN GAS CO             ELIZABETHTOWNGASCO.1993.txt             1993

  3    12/22/1993    DISNEY WALT CO                   DISNEYWALTCO.1993.txt                   1993

  4    12/23/1993    INTERNATIONAL GAME TECHNOLOGY    INTERNATIONALGAMETECHNOLOGY.1993.txt    1993

  5    01/06/1994    FRANKLIN RESOURCES INC           FRANKLINRESOURCESINC.1993.txt           1993

  6    01/12/1994    ADC TELECOMMUNICATIONS INC       ADCTELECOMMUNICATIONSINC.1993.txt       1993

  7    01/13/1994    MORTGAGE & REALTY TRUST          MORTGAGE&REALTYTRUST.1993.txt           1993

  8    01/13/1994    SUMMIT SECURITIES INC /ID/       SUMMITSECURITIESINC/ID/.1993.txt        1993

  9    01/18/1994    DUPLEX PRODUCTS INC              DUPLEXPRODUCTSINC.1993.txt              1993

10    01/26/1994    BOWNE & CO INC                   BOWNE&COINC.1993.txt                    1993

Linlin

Ask a Question
Discussion stats
  • 2 replies
  • 163 views
  • 0 likes
  • 3 in conversation