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

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

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

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;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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...

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 2 replies
  • 521 views
  • 2 likes
  • 3 in conversation