Hello Everyone,
I have the following data with me which has company_name, url, and filing_date:
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 |
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.
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");
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
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.