BookmarkSubscribeRSS Feed
AliRKM
Obsidian | Level 7

Hi all,

 

I have run a procsurvey freq on many variables and would like to print the CrossTabs where all variables have (or do not have) a specific value

Is there a way to stipulate something like:

proc print...;

where (var2 var2 var3) ne .;

?

 

This is a sample of the data - sorry so long but most people have subpop=0

data WORK.EXAMPLE;
infile datalines dsd truncover;

input DUPERSID:$8. REGIONY1:32. SEX:32. HISPANX:32. RTHLTH1:32. MNHLTH1:32. ADSMOK2:32. INSCOVY1:32. PMDINSY1:32. subpop:32. other_race:32. white:32. afr_am:32. a65_69:32. a70_74:32. a75_79:32. over80:32. married:32. div_sep:32. widowed:32. nev_marry:32. n
o_hs:32. hs_ed:32. more_hs:32. priv_ins:32. pub_only:32. no_ins:32. good_mhealth:32. norm_undwt:32. overwt:32. obese:32. vobese:32. polypharm:32.;

label DUPERSID="PERSON ID (DUID + PID)" REGIONY1="CENSUS REGION AS OF 12/31/13" SEX="SEX" HISPANX="HISPANIC ETHNICITY (EDITED/IMPUTED)" RTHLTH1="PERCEIVED HEALTH STATUS - RD 1" MNHLTH1="PERCEIVED MENTAL HEALTH STATUS - RD 1" ADSMOK2="SAQ: CURRENTLY SMOKE,R
2" INSCOVY1="HEALTH INSURANCE COVERAGE INDICATOR 13" PMDINSY1="PMED INSURANCE ANY TIME IN R3";
datalines;
10002101 1 1 2 3 3 1 2 2 1 0 0 1 1 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 1 0 0 1
10005101 4 2 2 3 3 2 2 2 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 0 1 0 1 0 0 0 1 1
10014101 1 2 2 4 4 2 1 1 0 0 1 0 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 0 0 0 1
10019102 2 2 2 3 3 2 1 2 0 0 1 0 0 1 0 0 0 0 1 0 0 0 1 1 0 0 1 0 0 1 0 1
10027101 1 1 2 3 1 2 2 2 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 1 0 1 1 0 0 0 1
10027102 1 2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0 1 0 0 0 1 1 0 0 1 0 0
10302102 3 1 2 2 2 2 1 2 0 0 1 0 . 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 0 0 0
10305101 2 2 2 3 2 2 2 2 0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1
10311101 3 2 2 3 3 2 2 2 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 0 1 0 1 0 0 0 1 1
10316101 2 2 2 4 4 1 2 2 1 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 1 1
10327101 2 2 2 3 2 2 1 2 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1
;;;;

I tried this with no luck

 

where subpop=1 and (F_a65_69 -- pmdinsy1 ne .);

 Maybe an array but isn't that only in data steps?

 

 

As you can see form below, my variable names have no pattern to them.

 

ods output Crosstabs=out;
proc surveyfreq data=meps.analysis;
strata varstr;
cluster varpsu;
weight poolwt;
tables subpop*(a65_69 a70_74 a75_79 over80 sex white afr_am other_race hispanx  married div_sep widowed nev_marry no_hs hs_ed more_hs inscovy1   rthlth1  mnhlth1 norm_undwt overwt obese vobese  adsmok2 curr_smoke polypharm   pmdinsy1 );
run;

proc print data=out;
where subpop=1;
var Frequency WgtFreq StdDeva65_69 a70_74 a75_79 over80 sex white afr_am other_race hispanx  married div_sep widowed nev_marry no_hs hs_ed more_hs inscovy1   rthlth1  mnhlth1 norm_undwt overwt obese vobese  adsmok2 curr_smoke polypharm   pmdinsy1;
run;

 

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Instead of

where subpop=1 and (F_a65_69 -- pmdinsy1 ne .);

 

How about

where subpop=1 and nmiss(of F_a65_69 -- pmdinsy1) = 0;
 
--
Paige Miller
AliRKM
Obsidian | Level 7
No luck: Got this in the log:

26 proc print data=out;
27 where subpop=1 and nmiss(of F_a65_69 -- pmdinsy1) = 0;
________
22
76
ERROR: Syntax error while parsing WHERE clause.
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN,
CONTAINS, EQ, GE, GT, LE, LIKE, LT, NE, OR, ^=, |, ||, ~=.
ERROR 76-322: Syntax error, statement will be ignored.

Tried parenthesis:
where subpop=1 and nmiss(of (F_a65_69 -- pmdinsy1)) = 0;

and got this:
ERROR: WHERE clause operator requires numeric variables.
Tom
Super User Tom
Super User

You cannot use variable lists in WHERE statement. They essentially follow the SQL rules, not the regular SAS rules.  Positional variable lists would probably be difficult anyway.

You can use an IF statement in a DATA step.

data x;
 set sashelp.class;
 if cmiss(of name -- weight);
run;

 

PGStats
Opal | Level 21

You can always use a data view like this:

 

data mySubset / view=mySubset;
set out;
if subpop=1 and cmiss(F_a65_69 -- pmdinsy1) = 0;
run;

proc print data=mySubset; ...
PG
AliRKM
Obsidian | Level 7

Still no luck:

NOTE: A stored DATA STEP view cannot run under a different operating system.

the output is blank.

 

I tried to read up on the note but did not understand the comments. Nor do I understand what a data view is - again, despite reading up on it. I have no technical background, my statistics is shaky so this is all beyond me 😞

Thanks for your help.

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!

What is Bayesian Analysis?

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.

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
  • 5 replies
  • 680 views
  • 2 likes
  • 4 in conversation