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

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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.

 

 

 

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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.

 

 

 

--
Paige Miller
Tom
Super User Tom
Super User

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.

OzanKirtac
Fluorite | Level 6

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;

  

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 989 views
  • 3 likes
  • 3 in conversation