Statistical Analysis System (SAS)

115

Solutions

136

Contributors

The Statistical Analysis System (SAS) programs consist of two steps, the DATA step and the PROC step. The DATA step reads data and prepares it for use by subsequent DATA or PROC steps. A SAS procedure (PROC) is a collection of statements that execute a certain task. SAS procedures have their own statements and commands, but many are shared among procedures. JMP is the graphical user interface for SAS, and is used in applications such as Six Sigma, quality control and engineering, design of experiments and scientific research.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi everyone!
I am trying to do a few things in my bash script (script1.sh):  pass logicals/variables to my SAS program (program1.sas), execute SAS code (program1.sas), check with "errstat" for specific errors related to SAS code conditions that I set up in my SAS code, and also check with "logerrchk" SAS log file for any errors in the SAS log.  
I think most of the script is correct but I am not sure about both checking errors (errstat" and "logerrchk").

 Please note: variable/logicals (file1, file2, plog, and errstat) are also defined in the SAS program.  

 Please provide any suggestions or examples if you can.
 Here is what I have so far:

#!/bin/bash
#script1.sh

# Creating variables for directories
export DATADIR1=/root/alldirs/2018/data1
export DATADIR2=/root/alldirs/2018/data2
export DATADIR3=/root/alldirs/2018/data3
export PROGDIR1=/root/alldirs/2018/prog1

#Creating variables for data files that are used in program1.sas and final log file 
export file1=${DATADIR1}/sasdata1.sas7bdat
export file2=${DATADIR2}/sasdata2.sas7bdat
export plog=${DATADIR3}/sas_program.log

#executing SAS program
sas ${PROGDIR1}/program1.sas -log ${DATADIR3}/program1.log

#checking for errors in SAS log file
logerrchk=$?     
   if [[ "$logerrchk" !=0 ]]; 
   then 
       echo "--- Error: Abnormal end in program program1.sas. Check log file! ---" >> $plog
       exit 2
   else
       echo "--- Program1.sas run successfully! ---" >> $plog
   fi
  
#checking for specific errors 

Open in new window

0
Cloud Class® Course: Microsoft Azure 2017
LVL 12
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Hi everyone!
I am trying to do a few things in my bash script (script1.sh):  pass logicals/variables to my SAS program (program1.sas), execute SAS code (program1.sas), check for errors, write all messages to a log file (sas_program.log), and also execute another script (script2.sh) which has a few directory logicals/variables shortcuts.

Please note: variable/logicals (file1, file2, plog, and stat) are also defined in the SAS program.  

Please provide any suggestions or examples if you can.
Here is what I have so far:

#script1.sh

#!/bin/bash

#executing script2.sh script 
source script2.sh

# Creating variables for directories
export DATADIR1=/root/alldirs/2018/data1
export DATADIR2=/root/alldirs/2018/data2
export DATADIR3=/root/alldirs/2018/data3
export PROGDIR1=/root/alldirs/2018/prog1


#Creating variables for data files that are used in program1.sas and final log file 
export file1=DATADIR1/sasdata1.sas7bdat
export file2=DATADIR2/sasdata2.sas7bdat
export plog=DATADIR3/sas_program.log

#Setting stat variable for future use
stat=0

#executing SAS program, checking for errors, and writing all messages to a log file 
sas ${PROGDIR1}/program1.sas -log ${DATADIR3}program1.log
stat=$?
   if [[ "$stat" !=0 ]]; 
     then echo -e "--- Error: Abnormal end in program program1.sas. Check log file! ---" >> $plog
    exit 2
             echo -e "--- Program1.sas run successfully! ---" >> $plog
   fi
exit 0

Open in new window




Any suggestions would be appreciated!
Thank you!
0
Need to convert below sas code to pseudocode.

sum ((case when (mod_r in ('02') and CAL IN ('P') and fec_in <= intnx('month', "PAR_FEC"d, -1, 'end') and EST not in ('7' '07' ' 7' '7 ' '70')
              and temp>0) then temp*SAL_OBL else . end)) as con_temp.
0
Hi,

We are working with a marketing strategy  for assisting surveying certain areas.  The front end is a screen with a series of questions which will later be analyzed.  Our concern to EE  is how can we protect or make sure that visitors are not repeating the questionair.   Also, detect if same ip or if the visitors somehow hiding their ip.  We are trying to assure the visitors is one visit per actual visit to the pages, no repeats.

Please advice.
0
How can I write an export command which gives me the same result as a manual export in SAS. When I do the manual export each record is on a separate line.  When I try using Proc Export my output is one continuous line.  I am trying to output a comma delimited text file.
0
Object oriented design is used to identify and define all program object that must work together.
0
I need help with writing an explicit pass through query in SAS eg.

I am two tables from the test schema, test.tableA and test.tableB.   TableB is a huge table and I need to pull 5 records from tableB  where they match in tableA.  I am thinking that an explicit pass through would be the best way to execute this because of the run time.  So from tableB, I need sample_A, sample_B, sample_C, sample_D, sample_E.  The sampleA column is a date field and I would need to select a particular day to shorten the run time and the result set.  From tableA, I need columnT, columnX, columnAA.  In tableB, the sampleE column is the primary key and in tableB, columnX is the key that can be used to join on.

Any help is appreciated.
0
I have created two sheets with date field, wrkorder no , hours and invoice count of technicians. One sheet shows day and other shows week numbers. The problem I’m facing is in the weeks sheet where even though the wrkorder happened twice in two dates the hours are adding up and sum of hours for each work order is showing. The total hours are accurate thought but invoicecount is getting wrong. Since a wrkorder happened in both days it is counted  as two but it showing me one.
0
A user I support needs me to purchase the JMP software (which is available from the https://www.sas.com/jmpstore/software/jmp/prodJMP.html website).

I have visited this website and have found that this software is being sold for $1,700.

Are there any other places or vendors where the full version of this software can be purchased for less?
0
Hello everyone,
I am trying to create XML record counts in the XML data file header.
Below code creates a XML data file "FinalXMLDataFile" from a SAS dataset "NewData" and the code works fine except counts are not working at all. Current record counts "previousCount" creates "0" counts in the XML Header in the counts section.  

Please let me know where the issue with record counts might be?

libname   mydir '/mydirectory'; 
filename outxml  '/mydirectory/FinalXMLDataFile.xml';

/* Macro variables to provide appropriate tab spacing */
%let tab="   ";
%let tab2="      ";
%let tab3="         ";
%let tab4="            ";
%let previousCount = 0; 


/*XML file information and headers*/
data _null_;
    file outxml;

if _N_ = 1 then
    do;
    
    put '<?xml version="1.0" encoding="UTF-8"?>';
    put '<XMLFile >';	
    put &tab. '<Header>';  
    put &tab2. "<CaseCount>%trim(&previousCount)</CaseCount>";     /* get record count of all XML records */ 
    put &tab2. '<Year>2017</Year>';
    put &tab. '</Header>';
    put &tab. '<Payload>';
    end;
run;

/* Using SAS dataset to create similar XML data file */
data _null_;
    file outxml mod;
    set mydir.NewData NOBS=lst;

    record = _N_ + &previousCount;
    
    if _n_=1 then do;
        put &tab2. '<MasterFile>'; 
    end;

    /*All Data records */
    put &tab3. '<AllData>'; 
    put &tab4. '<unit:VAR1>' VAR1+(-1)'</unit:VAR1>';
    put &tab4. '<unit:VAR2>' 

Open in new window

0
Cloud Class® Course: Microsoft Exchange Server
LVL 12
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

I need to create a matrix type calendar query that will replace rows that have zero value with 2 as the value in the summary column. This query is based on a file that runs monthly and daily. The file doesn't run on weekends or holidays.  In my query, The max_month column values are compared with the summary column values. If there are missing months in the summary column than the missing values are replaced with zeros. The last step is to output the data set to a text file.  My query isn't  outputting any results.
 
In the attachment, there is a text file name tran_sumary and an excel file name month.xls.  The tran_sumary file is a data file and month.xls is an example of what my query results need to print
 
 
create table xxx as 
select  * from connection to teradata
   (SELECT
       FROM
       b.LD_T,
       b.K_KY

/* create derived table b  and select the columns– extracts K_KY dates in the format of example SEP and print the K_KY largest count - b(<column list>)*/

    (select
       b.LD_T,
       b.K_KY
        cast(cast( b.K_KY as char(3)) as date format 'MMM')  AS MAX_MNTH,
        cast(cast(b.K_KY as char(8)) as date format 'yyyymmdd')  AS tran_dt
        from dy b
        Group BY 1,2
         Having Count(*) >1;)  AS b(LD_T,  MAX_MNTH, tran_dt)

/* create derived table c and select the columns – extracts sumary_end-dt dates in the format for example SEP and print the sumary_end-dt largest  count b(<column list>)*/ */

       (SELECT
          FROM
   

Open in new window

0
sas date in teradata

date1
20171101
20171101
How do you convert a date column stored as sas date value in teradata to a sas date format using proc sql? I am getting an error message.

Here is my code:

   
  proc sql;
  Create table test
   AS
   select cast(cast(date1 as date format 'YYYY/MM/DD') as char(10)) as 'date_d'
   from td2.db;

Open in new window

0
Hey, All,

Can you give me some good web links to where it has some very good Data Scientist Resume samples? Also, those samples are one-pagers (everyone desire one page resumes)

Thanks
0
Why Statistics is important for Data Analysis?
What is the role of Statistics in Data Analysis?

*Please share a real life example.*
0
I want to be data analyst.
but i don't know, what should i learn first?

what are basic capabilities  should i have ?
0
I am trying to embed automatically today's date (DDMMYYD10.) and XML records counts in the XML data file header. Is there an automatic way in SAS how to do that?

This is where today's date and record counts would go:
 
put &tab2. '<SampleDate>2017-06-27</SampleDate>';
 put &tab2. '<CaseCount>10</CaseCount>';

Open in new window


Full SAS code:
filename DirectX  "&basepath\examples\XMLData2.xml";
filename Complete "&basepath\examples\XMLComplete2.xml";

libname xmldir xmlv2 xmlfileref=DirectX xmltype=generic;

/* Macro variables to provide appropriate tab spacing */
%let tab="    ";
%let tab2="        ";

/* Writing two SAS datsets to xmldir library and creating XMLData.xml data file */ 
data xmldir.class(label="dataset class from sashelp library");
       set sashelp.class(obs=10);
run;

data xmldir.cars(label="dataset cars from sashelp library");
       set sashelp.cars(obs=10); 
run; 

libname xmldir clear;

/*  XML file information and header and XML File End*/
data _null_;
 infile	DirectX end=last;
file	Complete;

input;				
 
if _N_ = 1 then
    do;  
	put _infile_;	
    put '<Schema Name="CarsAndClass">';
    put &tab. '<Header>';
    put &tab2. '<SampleDate>2017-06-27</SampleDate>';
    put &tab2. '<CaseCount>10</CaseCount>';
    put &tab2. '<Action>Initial</Action>';
    put &tab2. '<YearPeriod>2017</YearPeriod>';
    put &tab. '</Header>';
    put &tab. '<Payload>';
    end;
else
	put &tab2 _infile_;	
 
if last then
    do;
    put &tab'</Payload>';		
    put '</Schema>';
    end;    
run;

Open in new window

0
Hello All Experts,
I am a student enthusiast in learning "Data Analytics" , which is the best platform to learn for FREE?
I want to Learn 'Data Science (Statistics)' & 'SAS/R' from scratch?
Any videos? Any websites? Any Blogs?

Thanks,

Regards,
Satish Kumar G N
0
Hello,
I am trying to add a header and tabs with info about the XML data file to .xml file in SAS code. How exactly this can be done? Please see what I have currently I have for my SAS code. I can see the XML data file as my output but the Header (tab and tab2) with all info about the XML file does not show up yet in the XML file.
 
libname xmldir xmlv2 '/basepath/examples/XMLData.xml' xmltype=generic;

/* Req. 1: Macro variables to provide appropriate tab spacing. */
%let tab="    ";
%let tab2="        ";

/* Req. 2: XML file information and header*/
data _null_;
   file xmldir;
  
    put '<?xml version="1.0" encoding="UTF-8"?>';
    put '<Schema Name>';
    put &tab. '<Header>';
    put &tab2. '<SampleDate>2017-06-14</SampleDate>';
    put &tab2. '<CaseCount>30</CaseCount>';
    put &tab2. '<Action>Initial</Action>';
    put &tab2. '<YearPeriod>2017</YearPeriod>';
    put &tab. '</Header>';
    put &tab. '<Payload>';
run;

/* Req. 3: Writing two SAS datsets to xmldir library and creating XMLData.xml data file*/ 
data xmldir.dataname1(label="dataset name1 from sashelp library");
       set sashelp.dataset1(obs=10);
run;

data xmldir.dataname2(label="dataset name2 from sashelp library");
       set sashelp.dataset2(obs=20 keep=var1 var2); 
run; 

libname xmldir clear;

/* Req. 4: XML File End*/
data _null_;
   file xmldir mod;

    put &tab'<Payload>';
    put '</Schema Name>';
run;

Open in new window


So, currently only Req. 3 is working.
Any comments or suggestions will be greatly appreciated!
0
Hello,
For testing and verification purposes, I am trying to compute the count of good duplicates found in both Data1 and Data2  and in Data3, and in one or the other. These are the steps I am trying to accomplish to get to my final results:

#1.  Create a list (Data4) of unique Data1 and Data2 where variable rec_flag=A, B, C, D.
#2.  Build a duplicate (Data5) file from the list in #1 by generating a record linking each two records where Var3 and Var4 are linked to the same Var6 and Var7.
#3.  Match Data5 file with Data3 where variable rec_flag=B, C, D using key variables Var3, Var4, Var6, and Var7.
#4.  Display in the output .lis the number of records in:
     #4.1 Both Data5 and Data3
     #4.2 Data5 only
     #4.3 Data3 only
 
The issue that I am having is with #2 where I need to build a duplicate file Data5.

Here is my SAS code below with missing step #2:

libname mydir "/home/myprofile/links"; 
%macro cnt_lnks;

 /*  #1 */
proc sort data=mydir.Data1
          out=Data1out(where=(rec_flag='A', 'B', 'C', 'D') keep=Var3 Var4 Var6 Var7 rec_flag);
          by Var3 Var4 Var6 Var7;
run;

proc sort data=mydir.Data2
          out=Data2out(where=(rec_flag='A', 'B', 'C', 'D') keep=Var3 Var4 Var6 Var7 rec_flag);
          by Var3 Var4 Var6 Var7;
run;

/*********************************************
 Datastep: merge Data1 & Data2
           by Var3 Var4 Var6 Var7
 ********************************************/
data all_links1;
  merge 

Open in new window

0
Cloud Class® Course: MCSA MCSE Windows Server 2012
LVL 12
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Hello everyone,
In my organization we are currently in a process transferring from using ASCII files to using XML data files when working (importing and exporting) with SAS datasets.  

So, my question is:  what would be a proper way to export multiple ( two or more) SAS datasets (dataset1, dataset2) to one XML data file (XMLData) and at the same time to make sure that XML data file actually has those multiple SAS datasets in it as tables.

The only way that I was able to export multiple SAS datasets to one  XML data file is by appending one SAS dataset to another but that's not what I want because at the end the XML data file does not have multiple tables in it - all data from multiple SAS datasets look as just one big table.  Below is working code but again it only appends multiple SAS datasets and it does not create tables in the XML data file.

libname xmldir xmlv2 '/home/profile1/xml/XMLData.xml' xmltype=generic;
libname mydir '/home/profile/sas';

data xmldir.XMLData;
       set mydir.dataset1
             mydir.dataset2; 
run; 

Open in new window


If you know how tackle this problem from any angle please let me know.  Any help would be very appreciated!
0
hi,

both SAS and IBM Cognos is analytical SW, any diff between them? I am wondering why company use both?
0
hi  i have code like this  File inputFile = new File(templateDownloadRequestDto.getTemplateName().trim() + ".xlsx");
this line is showing as path manipulation issue HP fotify scanning, from UI level i select a drop down value to download a file, then i hits a spring controller, from spring service we prepare xlsx sheet using apache poi ,here we are not validating any file names, because those are predefined names, so no need to validate file, how can i resolve this issue ?
0
Experts,

Can someone tell me what this SAS code doing.  It appears to be a macro in a macro.
CDPS.txt
0
Does anyone know that what would be used in SAS for LOGEST Function in Excel?
0
Experts,

I currently have my password assigned in a process that executes when SAS Enterprise Guide comes up.  I also have my libraries which require my password assigned in the same process.

This works fine for me, but I am concerned that those who may have access to the SAS tables in the background may be able to see my password.  In the past I have used the encrypted password, but the Teradata tables that require my password will not accept the encrypted SAS password.  

Is there a way I can be prompted to enter my password and then it is passed to the library assignments that are now in the "submit SAS code when server is connected"
0

Statistical Analysis System (SAS)

115

Solutions

136

Contributors

The Statistical Analysis System (SAS) programs consist of two steps, the DATA step and the PROC step. The DATA step reads data and prepares it for use by subsequent DATA or PROC steps. A SAS procedure (PROC) is a collection of statements that execute a certain task. SAS procedures have their own statements and commands, but many are shared among procedures. JMP is the graphical user interface for SAS, and is used in applications such as Six Sigma, quality control and engineering, design of experiments and scientific research.

Top Experts In
Statistical Analysis System (SAS)
<
Monthly
>

No Top Experts for this time period. Answer questions to earn the title!