GoGoGraph Reference Guide - Data

Data

Creating Temporary Formats

proc format;
    value $gender_m 'M' = 'Male'
                     'F' = 'Female'
                     ' ' = 'Missing';
 
    value $gender_mx_ns (notsorted) 'M' = 'Male'
                                    'F' = 'Female'
                                    ' ' = 'Missing'
                                    'X' = 'Unknown';
 
    value $gender_long 'M'='Gender:Male'
                      'F'='Gender:Female';
 
    value $gender_longnum 'M'='1:Male'
                           'F'='2:Female';
 
    value $gender_longchar '1:Male'='Gender:Male'
                           '2:Female'='Gender:Female';
run; 

Creating Temporary Datasets

data gender (drop=i);
    do i=1 to 23;
        gender='F';
        output;
    end;
    do i=1 to 15;
        gender='M';
        output;
    end;
run;
 
*---------------------------------------------------------;
 
ods exclude onewayfreqs;
ods output onewayfreqs=gender_freq (keep=gender frequency percent);
proc freq data=gender;
    table gender;
run;
 
proc datasets lib=work nolist;
    modify gender_freq;
    format _all_;
    *attrib _all_ label=' ';
    run;
quit;
 
*---------------------------------------------------------;
 
data gender_freq_multi;
    gender='F'; frequency=10; output;
    gender='F'; frequency=13; output;
    gender='M'; frequency=15; output;
run;
 
*---------------------------------------------------------;
 
data gender_m;
    set gender end=eof;
    output;
    if eof then
    do;
        gender=' ';
        output;
    end;
run;
 
*---------------------------------------------------------;
 
ods exclude onewayfreqs;
ods output onewayfreqs=gender_m_freq (keep=gender frequency percent);
proc freq data=gender_m;
    table gender / missing;
run;
 
proc sort data=gender_m_freq out=gender_m_freq;
    by frequency;
    format _all_;
run;
 
*---------------------------------------------------------;
 
ods exclude table;
ods output table=gender_mx_freq (drop=_TYPE_ _PAGE_ _TABLE_
                                 rename=(N=frequency PctN_0=percent));
proc tabulate data=gender_m;
    class gender / preloadfmt order=data missing;
    table gender*(n pctn)/ printmiss;
    format gender $gender_mx_ns.;
run;
 
*---------------------------------------------------------;
 
data gender_age (drop=i);
    gender='F';
    do age=12; do i=1 to 4; output; end; end;
    do age=13; do i=1 to 6; output; end; end;
    do age=14; do i=1 to 2; output; end; end;
    do age=15; do i=1 to 5; output; end; end;
    do age=16; do i=1 to 6; output; end; end;
 
    gender='M';
    do age=12; do i=1 to 2; output; end; end;
    do age=13; do i=1 to 7; output; end; end;
    do age=14; do i=1 to 2; output; end; end;
    do age=16; do i=1 to 4; output; end; end;
run;
 
*---------------------------------------------------------;
 
ods exclude onewayfreqs;
ods output onewayfreqs=gender_age_freq (keep=gender age frequency);
proc freq data=gender_age;
    by gender;
    table age;
run;
 
proc datasets lib=work nolist;
    modify gender_age_freq;
    format _all_;
    run;
quit;
 
*---------------------------------------------------------;
 
data gender_age_freq_15;
    set gender_age_freq (where=(age=15))
        gender_age_freq (where=(age=12))
        gender_age_freq (where=(age=16))
        gender_age_freq (where=(age=13))
        gender_age_freq (where=(age=14));
run;
 
*---------------------------------------------------------;
 
ods exclude crosstabfreqs;
ods output crosstabfreqs=gender_age_freq0_17
                         (keep=_type_ gender age frequency percent
                          where=(_type_='11'));
proc freq data=gender_age;
    table gender*age;
run;
 
data gender_age_freq0_17;
    set gender_age_freq0_17 (drop=_type_) end=eof;
    output;
    if eof then
        do;
            gender='M'; age=17; frequency=0; percent=0; output;
            gender='F'; age=17; frequency=0; percent=0; output;
        end;
    format _all_;
    attrib _all_ label=' ';
run;
 
*---------------------------------------------------------;
 
ods exclude onewayfreqs;
ods output onewayfreqs=age_freq (keep=age frequency percent);
proc freq data=gender_age;
    table age;
run;
 
proc datasets lib=work nolist;
    modify age_freq;
    format _all_;
    run;
quit;
 
*---------------------------------------------------------;
 
proc sql;
    create table gender_age_result
                (gender char(1), age num, result num);
 
    insert into gender_age_result
        values ('M',12,110)
 
        values ('F',12,110)
        values ('F',12,116)
        values ('F',12,122)
        values ('F',12,119)
 
        values ('F',13,127)
        values ('F',13,130)
        values ('F',13,125)
        values ('F',13,125)
        values ('F',13,121)
        values ('F',13,127)
 
        values ('F',14,138)
        values ('F',14,132)
 
        values ('F',15,142)
        values ('F',15,150)
        values ('F',15,138)
        values ('F',15,143)
        values ('F',15,148)
 
        values ('F',16,168)
        values ('F',16,170)
        values ('F',16,185)
        values ('F',16,173)
        values ('F',16,155)
        values ('F',16,192)
 
        values ('M',12,114)
 
        values ('M',13,122)
        values ('M',13,125)
        values ('M',13,132)
        values ('M',13,128)
        values ('M',13,118)
        values ('M',13,122)
        values ('M',13,127)
 
        values ('M',14,133)
        values ('M',14,128)
 
        values ('M',16,158)
        values ('M',16,168)
        values ('M',16,155)
        values ('M',16,165);
quit;
 
*---------------------------------------------------------;
 
data gender_age_yr_result;
    set gender_age_result (in=_2017)
        gender_age_result (in=_2018 where=(age <15));
    if _2017 then yr=2017;
    else
        do;
            if gender='M' then result=result+5;
            else if gender='F' then result=result+3;
            yr=2018;
        end;
run;
 
*---------------------------------------------------------;
 
data gender_age_yr;
    set gender_age_yr_result (drop=result);
run;
 
*---------------------------------------------------------;
 
data gender_result;
    set gender_age_result (drop=age);
run;
 
*---------------------------------------------------------;
 
ods exclude summary;
ods output summary=gender_result_mean;
 
proc means data=gender_result nonobs sum mean median min max;
    class gender;
    var result;
run;
 
proc datasets lib=work nolist;
    modify gender_result_mean;
    format _all_;
    attrib _all_ label=' ';
    run;
quit;
 
*---------------------------------------------------------;
 
ods exclude summary;
ods output summary=gender_yr_result_mean (drop=nobs);
proc means data=gender_age_yr_result mean;
    class gender yr;
    var result;
run;
 
proc transpose data=gender_yr_result_mean
               out=gender_yr_result_mean (drop=_name_)
               prefix=result_mean_;
    by gender;
    var result_mean;
    id yr;
    format _all_;
    attrib _all_ label=' ';
run;
 
*---------------------------------------------------------;
 
ods exclude summary;
ods output summary=age_result_mean;
proc means data=gender_age_yr_result nonobs mean;
    class age;
    var result;
run;
 
proc datasets lib=work nolist;
    modify age_result_mean;
    format _all_;
    attrib _all_ label=' ';
    run;
quit;
 
*---------------------------------------------------------;
 
proc sql;
    create table gender_course_mark_freq
    (gender char(1), course char(7), mark num, frequency num);
 
    insert into gender_course_mark_freq
        values('F','Math',   60,1)
        values('F','Math',   65,4)
        values('F','Math',   85,2)
        values('F','Math',   80,3)
 
        values('F','History',60,3)
        values('F','History',55,3)
        values('F','History',75,2)
        values('F','History',85,2)
 
        values('M','Math',   60,1)
        values('M','Math',   65,4)
        values('M','Math',   80,3)
        values('M','Math',   85,2)
 
        values('M','History',45,3)
        values('M','History',55,3)
        values('M','History',60,6)
        values('M','History',70,5)
        values('M','History',85,2)
        values('M','History',90,1)
 
        values('M','English',75,20);
quit;
 
*---------------------------------------------------------;
 
data shoes (where=(not(region='Canada' or
                       region='United States' and product='Slipper')));
    set sashelp.shoes(where=(product in ('Boot','Sandal','Slipper',"Men's Casual") and
                             region in ('Canada','United States')));
    output;
    region='North America';
    output;
run;
 
proc sort data=shoes out=shoes;
    by region subsidiary product;
run;
 
ods exclude summary;
ods output summary=shoes_sales_sum;
proc means data=shoes sum;
    by region subsidiary product;
    var sales;
run;
 
proc datasets lib=work nolist;
    modify shoes_sales_sum;
    format _all_;
    attrib _all_ label=' ';
    run;
quit; 

Creating Permanent Datasets

%*let xxtraining=<To Update>;
 
libname xxdata "&xxtraining./data";
 
proc copy in=work out=xxdata;
    select gender
           gender_freq
           gender_freq_multi
           gender_m
           gender_m_freq
           gender_mx_freq
           gender_age
           gender_age_freq
           gender_age_freq_15
           gender_age_freq0_17
           age_freq
           gender_age_result
           gender_age_yr_result
           gender_age_yr
           gender_result
           gender_result_mean
           gender_yr_result_mean
           age_result_mean
           gender_course_mark_freq
           shoes_sales_sum;
run;
 
libname xxdata clear; 

Copyright © 2024 xxformat GmbH, All Rights Reserved

xxformat GmbH

c/o STARTPLATZ, Im Mediapark 5
50670 Cologne
Germany

Amtsgericht Köln HRB 90276

Geschäftsführer: Véronique Bourcier
veronique.bourcier@xxformat.com
+49 1577 288 6066