Hi All
I have two issues:
1. The file attached named First has date format imported as string but I cannot change that to date numeric format YYMMDDN8.
2. The file attached named cik2 has 10 digit code v2 with zeros before 7 digit number. I want to transform this column from string to numeric but when I convert I keep loosing the zeros at the beginning of the number.
3. The v2 variable needs to have only 10 digit length but it has 79 charac space now.
All help is appreciated
Character strings can be converted to numeric using the INPUT() function and the proper informat.
data want;
set first;
filingdate1=input(filingdate,anydtdte10.);
format filingdate1 yymmddd10.;
run;
Regarding CIK2 converting it to numeric, why bother? It is soooo much easier to leave it as character. Strings like this don't need to be numeric, because you are not going to compute a mean or sum of these values. So that's my answer, use it as character.
3. The v2 variable needs to have only 10 digit length but it has 79 charac space now.
There is no v2 variable.
Character strings can be converted to numeric using the INPUT() function and the proper informat.
data want;
set first;
filingdate1=input(filingdate,anydtdte10.);
format filingdate1 yymmddd10.;
run;
Regarding CIK2 converting it to numeric, why bother? It is soooo much easier to leave it as character. Strings like this don't need to be numeric, because you are not going to compute a mean or sum of these values. So that's my answer, use it as character.
3. The v2 variable needs to have only 10 digit length but it has 79 charac space now.
There is no v2 variable.
So the FILINGDATE variable has mixed styles of how the dates are typed.
Here is one way that seems to work with this example.
data want1;
set "c:\downloads\first";
date = input(filingdate,??mmddyy10.);
if missing(date) then date=input(filingdate,??date11.);
format date yymmdd10.;
run;
proc freq ;
tables date*filingdate/ list missing;
run;
The variable CIK is the second variable in that CIK2 dataset.
To change the length of a character variable you need to set the new length before data step compiler "sees" the old one.
data want2;
length cik $10 ;
set "c:\downloads\chik2";
run;
I would NOT convert CIK to numeric, you will loose the leading zeros.
Thank you for the responses.
I want the date in the following format 20220123 so yymmddN8. must be the new format. so in the last linke format date yymmddN8.;
ata want1;
set "c:\downloads\first";
date = input(filingdate,??mmddyy10.);
if missing(date) then date=input(filingdate,??date11.);
format date yymmdd10.;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.