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;
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.
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.);
You have to create a new variable when converting.
data temp02; set temp02;
permno_num= input(permno, 8.);
run;
Thank you!
Hi, the first picture is the contents before converting format, the second is the log of changing format
@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.
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.
Thank you, that works!
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.