- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello guys,
In my data, "permno" is character value, i tried to convert it into numeric value, but it didn't work.
data temp02; set temp01;
if permno=. then delete;
format startdate enddate yymmddn8.;
keep permno StartDate enddate ticker;
run;
data temp02; set temp02;
permno= input(permno, 8.);
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It can't be done. Once a variable is character, it remains character forever. You can program around that. But first, to refer to missing values for a character variable, use a blank within quotes:
data temp02;
set temp01;
if permno = ' ' then delete;
format startdate enddate yymmddn8.;
keep permno StartDate enddate ticker;
run;
Your original syntax would be correct for a missing value for a numeric variable.
To get a numeric variable from the character PERMNO, you need to create a new variable:
data temp03;
set temp02
permno_c = input(permno, 8.);
run;
If you want to re-use the same variable name (PERMNO), you can add to the same DATA step:
data temp03;
set temp02;
permno_c = input(permno, 8.);
drop permno;
rename permno_c = permno;
run;
That's what it takes to come up with PERMNO as a numeric variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Could you elaborate on what you meant by didn't work ? post the log.
In this statement you are treating permno as if it is numeric
if permno=. then delete;
but in the next step you are trying to convert permno to numeric.
permno= input(permno, 8.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You have to create a new variable when converting.
data temp02; set temp02;
permno_num= input(permno, 8.);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi, the first picture is the contents before converting format, the second is the log of changing format
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Songchan wrote:
Hi, the first picture is the contents before converting format, the second is the log of changing format
Check the line of the code indicated in the log - Line 163 in your log will tell you exactly where in your code is the issue. Is that your conversion line? It helps if you show the full log. As others have indicated you cannot change in place, you need to rename the variable ... we could tell you what's wrong if you show the code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It can't be done. Once a variable is character, it remains character forever. You can program around that. But first, to refer to missing values for a character variable, use a blank within quotes:
data temp02;
set temp01;
if permno = ' ' then delete;
format startdate enddate yymmddn8.;
keep permno StartDate enddate ticker;
run;
Your original syntax would be correct for a missing value for a numeric variable.
To get a numeric variable from the character PERMNO, you need to create a new variable:
data temp03;
set temp02
permno_c = input(permno, 8.);
run;
If you want to re-use the same variable name (PERMNO), you can add to the same DATA step:
data temp03;
set temp02;
permno_c = input(permno, 8.);
drop permno;
rename permno_c = permno;
run;
That's what it takes to come up with PERMNO as a numeric variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, that works!