I am trying to figure out how to identify observations with a variable code of 391; however, some observations have a code of 0391, which has a different meaning in this database. This is probably a silly question, but I am new to SAS so any help would be appreciated!
Thanks so much!
Can you do a PROC CONTENTS on the data set and tell whether your variable of interest is character or numeric? If numeric, then these 2 WHERE statements would work the same:
WHERE numvar = 0391;
WHERE numvar = 391;
On the other hand, if you have a CHARACTER variable, then there is a difference between the string '391' and the string '0391'. Here's a program you can run to illustrate that point.
data testdata; infile datalines dlm=','; input numvar charvar $; datalines; 0,0 0391,0391 391,391 0011,0011 2220,2220 ; run; ods select variables; proc contents data=testdata; title '1) How are variables defined'; run; proc print data=testdata; title '2) where with NUMVAR'; where numvar = 0391; run; proc print data=testdata; title '3) alternative with NUMVAR'; where numvar = 391; run; proc print data=testdata; title '4) check CHARVAR'; where charvar = '0391'; run; proc print data=testdata; title '5) alternative with CHARVAR'; where charvar = '391'; run;
Note that in the TESTDATA data set, the same value is read as character and as numeric and then used with a WHERE in PROC PRINT. Reviewing the output shows the difference in numeric and character variables.
It is numeric; however, could i simply do a string if-then statement specifying = '391' ? Would that work?
Thanks so much!
There are no "leading zeros" on a number. The number 391 is the same as 0391 and 00391. If you need to distinguish between 0391 and 391 then you need read the original data as a character string.
If you need to distinguish 0391 from 391, you must create the variable as character when you extract it from the database. If your variable is numeric, all of these find the same observations:
where var = 391;
where var = 0391;
where var = 00391;
where var = 389+2;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.