Dear all
I am using the following codes to create a new sample
data Patstat_gb_hrm_set;
set Dataset.Patstat_hrm_gb_ori;
if SECTOR eq "COMPANY" or "COMPANY GOV NON-PROFIT" or "COMPANY GOV NON-PROFIT UNIVERSITY" or "COMPANY HOSPITAL" or "COMPANY UNIVERSITY";
run;
however, the result is
60 data Step1.Patstat_gb_hrm_set;
61 set Step1.Patstat_gb_hrm_set;
62 if SECTOR = 'COMPANY' or 'COMPANY GOV NON-PROFIT' or 'COMPANY GOV NON-PROFIT UNIVERSITY' or
62 ! 'COMPANY HOSPITAL' or 'COMPANY UNIVERSITY';
63 run;
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
62:26 62:54 62:93 62:115
NOTE: Invalid numeric data, 'COMPANY GOV NON-PROFIT' , at line 62 column 26.
NOTE: Invalid numeric data, 'COMPANY GOV NON-PROFIT UNIVERSITY' , at line 62 column 54.
NOTE: Invalid numeric data, 'COMPANY HOSPITAL' , at line 62 column 93.
NOTE: Invalid numeric data, 'COMPANY UNIVERSITY' , at line 62 column 115.
HRM_L2=20C citation=0 earliest_filing_month=JUN2006 application=1 PERSON_CTRY_CODE=GB PERSON_NAME=20C
HRM_LEVEL=1 SECTOR=UNKNOWN PERSON_ADDRESS=Bath & Northeast Somerset _ERROR_=1 _N_=77
NOTE: Invalid numeric data, 'COMPANY GOV NON-PROFIT' , at line 62 column 26.
NOTE: Invalid numeric data, 'COMPANY GOV NON-PROFIT UNIVERSITY' , at line 62 column 54.
NOTE: Invalid numeric data, 'COMPANY HOSPITAL' , at line 62 column 93.
NOTE: Invalid numeric data, 'COMPANY UNIVERSITY' , at line 62 column 115.
....
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
HRM_L2=A.J.N. * DE SOUSA citation=0 earliest_filing_month=FEB1992 application=1 PERSON_CTRY_CODE=GB
PERSON_NAME=A.J.N. * DE SOUSA HRM_LEVEL=1 SECTOR=UNKNOWN
PERSON_ADDRESS=31 HILLFIELD ROAD,COMBERTON,CAMBRIDGE,CB3 7DB _ERROR_=1 _N_=696
NOTE: There were 348020 observations read from the data set DATASET.PATSTAT_HRM_GB_ORI.
NOTE: The data set WORK.PATSTAT_GB_HRM_SET has 113423 observations and 9 variables.
NOTE: DATA statement used (Total process time):
real time 13.89 seconds
cpu time 1.39 seconds
Could you please give me some suggestion about this ? especially why Character values been converted to numeric values'?
thanks for your attention to this matter
Try this
data Patstat_gb_hrm_set;
set Dataset.Patstat_hrm_gb_ori;
/*if SECTOR eq "COMPANY" or "COMPANY GOV NON-PROFIT" or "COMPANY GOV NON-PROFIT UNIVERSITY" or "COMPANY HOSPITAL" or "COMPANY UNIVERSITY";*/
if SECTOR in ("COMPANY" "COMPANY GOV NON-PROFIT" "COMPANY GOV NON-PROFIT UNIVERSITY" "COMPANY HOSPITAL" "COMPANY UNIVERSITY");
run;
Try this
data Patstat_gb_hrm_set;
set Dataset.Patstat_hrm_gb_ori;
/*if SECTOR eq "COMPANY" or "COMPANY GOV NON-PROFIT" or "COMPANY GOV NON-PROFIT UNIVERSITY" or "COMPANY HOSPITAL" or "COMPANY UNIVERSITY";*/
if SECTOR in ("COMPANY" "COMPANY GOV NON-PROFIT" "COMPANY GOV NON-PROFIT UNIVERSITY" "COMPANY HOSPITAL" "COMPANY UNIVERSITY");
run;
The if statement requires:
if <condition> then ...
So logically you are saying:
if variable sector equals the string "COMPANY" is true
or the string "COMPANY GOV NON-PROFIT" is true (which is it because its not 0)
etc.
To use if like that you need to put variable and comparitor each time:
if sector="COMPANY" or sector="COMPANY GOV NON-PROFIT" or...
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.