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

Hello,

I would appreciate if someone could help me with the SAS code for storing final results at a file and retrieving the information directly from the stored dataset and using it without going through all the several steps.

Please find below this dataset and the SAS procedures used to arrive at the final dataset t2b.

Eg. if I complete work today and write final results to dataset t2b. Is there a code to directly obtain the stored information and use to for for say logistic regression without going though all the many steps?


/*DATASET 1*/
data idnew1;
input id$ job idchem;
datalines;
os1 1 990005
os1 1 990021
os1 1 211700
os1 2 211700
os1 2 990021
os1 2 210701
os1 2 990005
os2 1 210701
os2 1 990005
os2 2 990021
os2 3 210701
os2 3 990005
os3 3 210701
os3 1 211700
os4 1 210701
os4 1 990005
os4 1 211700
;

proc format;
value idchem
990005 = "cla_exp"
990021 = "bio_exp"
210701 = "amo_exp"
211700 = "chl_exp";
run;

data temp;
set idnew1;
dum = 1;
format idchem idchem.;
id_job=catx('_', id, job);
put _all_;
run;

proc sort data=temp; by id job id_job; run;

proc transpose data=temp out=idnew2(drop=_name_);
by id job id_job;
id idchem;
var dum;
run;
proc print data=idnew2;
Title "Table 1: Merged exposure files for cla, bio, amo and chl pollutants";
run;

/*Replacing missing values(.)with zeros(0) ie. unexposed*/
data t;
set idnew2;
proc stdize out=t2 reponly missing=0;
drop _type_;
run;
proc sort; by id job;
Title " Table 2: Merged exposure files for cla, bio, amo and chl pollutants: missing values replaced with zeros";

proc print data=t2; run;

/*FINDING FREQUENCIES OF ASSOCIATIONS*/
proc freq data=t2;
tables
cla_exp*bio_exp
cla_exp*amo_exp
cla_exp*chl_exp
bio_exp*amo_exp
bio_exp*chl_exp
bio_exp*chl_exp;

Title "Frequencies of associations between cla, bio, amo and chl pollutants";
run;

/* COUNTING EXPOSED IDS PER AGENT! GOOD! KEEP IT!*/
/* CHECKING NUMBER OF UNIQUE IDS*/

Proc summary data= t2 nway ;
class id;
var cla_exp bio_exp amo_exp chl_exp;
output out=t2b(drop=_type_ _freq_) max=;
run;
Title "Table of unique IDs for cla bio amo and chl";
proc print;


proc freq data=t2b;
tables cla_exp bio_exp amo_exp chl_exp;
Title "Unique ids frequecies for cla, bio, amo and chl";
run;

proc freq data=t2b;
tables
cla_exp*bio_exp
cla_exp*amo_exp
cla_exp*chl_exp
bio_exp*amo_exp
bio_exp*chl_exp
bio_exp*chl_exp;

Title "Frequencies of UNIQUE IDS exposure associations between cla, bio, amo and chl agents";
run;

Next time,I wish to start work directly form dataset t2b and not to run entire work again
ie. starting from dataset idnew1. Please find attached SAS log.

Thank you in advance.

ak.


1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

You can address table names in the form <libref>.<table name>

If you only use the table name in your code then SAS uses WORK as libref: WORK.<table name>

WORK is a location on your disk which SAS removes when you terminate a SAS session.

 

You can define a libname (or use an existing one) to define the path to a folder (on the SAS server side) where you want to store your SAS tables permanently. You then use this libref so the table doesn't get created in WORK but in the folder the libref points to.

 

At begin of a new SAS session just issue the libname statement again. This gives you access to all SAS tables created under this folder in earlier sessions.

libname mydata '<path to folder>';

proc freq data=mydata.t2b;
  tables cla_exp bio_exp amo_exp chl_exp;
  Title "Unique ids frequecies for cla, bio, amo and chl";
run;

View solution in original post

5 REPLIES 5
Shmuel
Garnet | Level 18

To keep results you need use your own assigned library.

Define a final library by

libname <final libref> <path to a folder>;   /* final library reference name */

then use it:

1) to keep the created formats by

proc format lib=<final libref> ;
   ... your code ...
run;

2) creating final data sets:

   

data <final libref>.<dataset name>;
    ...any code ...
run;

 

 

If you have any issue, post the log using the {i} icon on top this window.

ak2011
Fluorite | Level 6
 

Hello,

I would appreciate if someone could help me with the SAS code for storing final results at a file and retrieving the information directly from the stored dataset and using it without going through all the several steps.

Please find below this dataset and the SAS procedures used to arrive at the final dataset t2b.

Eg. if I complete work today and write final results to dataset t2b. Is there a code to directly obtain the stored information and use to for for say logistic regression without going though all the many steps?


/*DATASET 1*/
data idnew1;
input id$ job idchem;
datalines;
os1 1 990005
os1 1 990021
os1 1 211700
os1 2 211700
os1 2 990021
os1 2 210701
os1 2 990005
os2 1 210701
os2 1 990005
os2 2 990021
os2 3 210701
os2 3 990005
os3 3 210701
os3 1 211700
os4 1 210701
os4 1 990005
os4 1 211700
;

proc format;
value idchem
990005 = "cla_exp"
990021 = "bio_exp"
210701 = "amo_exp"
211700 = "chl_exp";
run;

data temp;
set idnew1;
dum = 1;
format idchem idchem.;
id_job=catx('_', id, job);
put _all_;
run;

proc sort data=temp; by id job id_job; run;

proc transpose data=temp out=idnew2(drop=_name_);
by id job id_job;
id idchem;
var dum;
run;
proc print data=idnew2;
Title "Table 1: Merged exposure files for cla, bio, amo and chl pollutants";
run;

/*Replacing missing values(.)with zeros(0) ie. unexposed*/
data t;
set idnew2;
proc stdize out=t2 reponly missing=0;
drop _type_;
run;
proc sort; by id job;
Title " Table 2: Merged exposure files for cla, bio, amo and chl pollutants: missing values replaced with zeros";

proc print data=t2; run;

/*FINDING FREQUENCIES OF ASSOCIATIONS*/
proc freq data=t2;
tables
cla_exp*bio_exp
cla_exp*amo_exp
cla_exp*chl_exp
bio_exp*amo_exp
bio_exp*chl_exp
bio_exp*chl_exp;

Title "Frequencies of associations between cla, bio, amo and chl pollutants";
run;

/* COUNTING EXPOSED IDS PER AGENT! GOOD! KEEP IT!*/
/* CHECKING NUMBER OF UNIQUE IDS*/

Proc summary data= t2 nway ;
class id;
var cla_exp bio_exp amo_exp chl_exp;
output out=t2b(drop=_type_ _freq_) max=;
run;
Title "Table of unique IDs for cla bio amo and chl";
proc print;


proc freq data=t2b;
tables cla_exp bio_exp amo_exp chl_exp;
Title "Unique ids frequecies for cla, bio, amo and chl";
run;

proc freq data=t2b;
tables
cla_exp*bio_exp
cla_exp*amo_exp
cla_exp*chl_exp
bio_exp*amo_exp
bio_exp*chl_exp
bio_exp*chl_exp;

Title "Frequencies of UNIQUE IDS exposure associations between cla, bio, amo and chl agents";
run;

Next time,I wish to start work directly form dataset t2b and not to run entire work again
ie. starting from dataset idnew1. Please find attached SAS log.

Thank you in advance.

ak.
Patrick
Opal | Level 21

You can address table names in the form <libref>.<table name>

If you only use the table name in your code then SAS uses WORK as libref: WORK.<table name>

WORK is a location on your disk which SAS removes when you terminate a SAS session.

 

You can define a libname (or use an existing one) to define the path to a folder (on the SAS server side) where you want to store your SAS tables permanently. You then use this libref so the table doesn't get created in WORK but in the folder the libref points to.

 

At begin of a new SAS session just issue the libname statement again. This gives you access to all SAS tables created under this folder in earlier sessions.

libname mydata '<path to folder>';

proc freq data=mydata.t2b;
  tables cla_exp bio_exp amo_exp chl_exp;
  Title "Unique ids frequecies for cla, bio, amo and chl";
run;

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 998 views
  • 0 likes
  • 3 in conversation