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

Attached an extraction from DC.input_analysis_res

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Well, I am not writing it for you.  Here is an example using sashelp.class and a input dataset.  Basically the idea is from your test metadata, to generate a call out to one of the test macros.  You can have as many test macros, or calls to them as you like:

data input_analysis_res;
  length variable_name_original variable_list variable_min variable_max $200;
  variable_name_original="NAME"; output;
  variable_name_original="SEX"; variable_list="M F"; output;
  variable_list="";
  variable_name_original="AGE"; variable_min="14"; variable_max="20"; output;
  variable_name_original="HEIGHT"; variable_min="57"; variable_max="63"; output;
  variable_name_original="WEIGHT"; variable_min="90"; variable_max="120"; output;
run;

proc sql;
  create table RESULTS (VAR char(200),TEST char(200),ID char(200),VAL char(200));
quit;

%macro Check_List (ds=,var=,vlist=);
  proc sql;
    insert into RESULTS 
    select  distinct
            "&VAR.",
            "In List",
            NAME,
            &VAR.
    from    &DS.
    where   &VAR. not in (&VLIST.);
  quit;
%mend Check_List;

%macro Check_Range (ds=,var=,vmin=,vmax=);
  proc sql;
    insert into RESULTS
    select  distinct
            "&VAR.",
            "Outside Range &VMIN. - &VMAX.",
            NAME,
            strip(put(&VAR.,best.))
    from    &DS.
    where   &VAR. not between &VMIN. and &VMAX.;
  quit;
%mend Check_Range;

data _null_;
  set input_analysis_res;
  if variable_list ne "" then 
    call execute(cats('%Check_List (ds=sashelp.class,var=',variable_name_original,',vlist="',tranwrd(strip(variable_list)," ",'" "'),'");'));
  if variable_min ne "" then 
    call execute(cats('%Check_Range (ds=sashelp.class,var=',variable_name_original,',vmin=',variable_min,',vmax=',variable_max,');'));
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 16 replies
  • 2215 views
  • 1 like
  • 2 in conversation