Hi All ,
I am quite new to SAS . Just started learning it . Please suggest what function best suits here .
Input File :
Total Exceptions Were Found
Exceptions Were ignored
Total Violations Were Found
============================================
Object : PLATFORM
Type : SOFTWARE
Attribute : LISENCE
Should Be : INTACT
Actual : INTACT
Standard : NO
===========================================
===========================================
Object : MACHINE
Type : HARDWARE
Attribute : CAPACITY
Should Be : AMPLE
Actual : UNDER
Baseline : YES
For the above Input file , how can I print it in Colum wise
Example :
Object Type Attribute Should Be Actual Standard
PLATFORM SOFTWARE LISENCE INTACT INTACT NO
MACHINE HARDWARE CAPACITY AMPLE UNDER YES
I tried to use the deliminartor but its not giving me the desired output .
Please suggest what function to use .
@sams54156 wrote:
Hi All ,
I am quite new to SAS . Just started learning it . Please suggest what function best suits here .
Input File :
Total Exceptions Were Found
Exceptions Were ignored
Total Violations Were Found
============================================
Object : PLATFORM
Type : SOFTWARE
Attribute : LISENCE
Should Be : INTACT
Actual : INTACT
Standard : NO
===========================================
===========================================
Object : MACHINE
Type : HARDWARE
Attribute : CAPACITY
Should Be : AMPLE
Actual : UNDER
Baseline : YESFor the above Input file , how can I print it in Colum wise
Example :
Object Type Attribute Should Be Actual Standard
PLATFORM SOFTWARE LISENCE INTACT INTACT NO
MACHINE HARDWARE CAPACITY AMPLE UNDER YESI tried to use the deliminartor but its not giving me the desired output .
Please suggest what function to use .
Your main issue is that the format you show for your file is a moderately (or worse depending on how regular the content is) complex file.
The basic SAS input statement for a delimited file expects all variables to be on a single row in the data. When you have values on multiple lines in a data set then you have to provide instructions on which lines to read which values.
Further complicating things is that each block of content (I am assuming as you did not say) appearing between the lines of
============================================
have different actual content. First you appear to have a header section that starts with the "Total Exceptions". You don't indicate if that should be kept.
Second you would want to read data only from lines after the divider.
Third is varying content.
The first block has Standard : NO but the second block has Baseline : YES . So "standard" does not seem to actually appear in the second block.
And also it appears that the number of divider lines may be different inside the file.
If every "record" has exactly 6 lines and you want the 6th line always be in a variable named Standard that is possible. IF not then a more complete description of the file and the desired result is going to be needed.
It is a good idea to post example input text in a code box opened with the forum {I} icon because the message windows here will "clean up" spaces and so the text you paste may not actually be what your file looks like.
This may get you started:
data work.raw; infile datalines truncover; length Object Type Attribute Should_Be Actual Standard dummy $ 15.; input @; if _infile_ =: "==============" then do; /* go to next line*/ input; input @':' object /@':' type /@':' Attribute /@':' Should_Be /@':' Actual /@':' Standard / dummy ; output; end; else input; drop dummy; datalines; Total Exceptions Were Found Exceptions Were ignored Total Violations Were Found ============================================ Object : PLATFORM Type : SOFTWARE Attribute : LISENCE Should Be : INTACT Actual : INTACT Standard : NO =========================================== =========================================== Object : MACHINE Type : HARDWARE Attribute : CAPACITY Should Be : AMPLE Actual : UNDER Baseline : YES =========================================== ; run;
The datalines is to simulate you input file. You would not include that. Instead the INFILE would point to your file.
The length statement sets the variables as character and provides an expected length for them. If you have a better idea of the actual content for each variable you can customize the length. Note that your variable "Should be" is not a valid SAS variable name so I place and _ instead of the space. Dummy is a variable to read the following =========== divider line.
@the first input @; brings the current line of the file into a buffer to examine with the SAS special variable _infile_.
If it starts with a number of ===== characters (the =: compares the start of a string) then that is a divider line.
@AT which point we use one input; to advance to the next line that should have data. The @':' instruction on the input line says to advance the read pointer in the file to that position to start reading data. The / say "go to the next line". The / dummy says to read the following divider line.
Some caveats: If there are not exactly the same number of rows of data in the same order each time this is not going to work.
This expects two rows of ========== between the blocks of data and that the last record has a =========== following it.
If the value of any of these variables has a space in it then only the first word will be read.
Proc print would be the way to display the results if that is what you meant by print them column wise.
@sams54156 wrote:
Hi All ,
I am quite new to SAS . Just started learning it . Please suggest what function best suits here .
Input File :
Total Exceptions Were Found
Exceptions Were ignored
Total Violations Were Found
============================================
Object : PLATFORM
Type : SOFTWARE
Attribute : LISENCE
Should Be : INTACT
Actual : INTACT
Standard : NO
===========================================
===========================================
Object : MACHINE
Type : HARDWARE
Attribute : CAPACITY
Should Be : AMPLE
Actual : UNDER
Baseline : YESFor the above Input file , how can I print it in Colum wise
Example :
Object Type Attribute Should Be Actual Standard
PLATFORM SOFTWARE LISENCE INTACT INTACT NO
MACHINE HARDWARE CAPACITY AMPLE UNDER YESI tried to use the deliminartor but its not giving me the desired output .
Please suggest what function to use .
Your main issue is that the format you show for your file is a moderately (or worse depending on how regular the content is) complex file.
The basic SAS input statement for a delimited file expects all variables to be on a single row in the data. When you have values on multiple lines in a data set then you have to provide instructions on which lines to read which values.
Further complicating things is that each block of content (I am assuming as you did not say) appearing between the lines of
============================================
have different actual content. First you appear to have a header section that starts with the "Total Exceptions". You don't indicate if that should be kept.
Second you would want to read data only from lines after the divider.
Third is varying content.
The first block has Standard : NO but the second block has Baseline : YES . So "standard" does not seem to actually appear in the second block.
And also it appears that the number of divider lines may be different inside the file.
If every "record" has exactly 6 lines and you want the 6th line always be in a variable named Standard that is possible. IF not then a more complete description of the file and the desired result is going to be needed.
It is a good idea to post example input text in a code box opened with the forum {I} icon because the message windows here will "clean up" spaces and so the text you paste may not actually be what your file looks like.
This may get you started:
data work.raw; infile datalines truncover; length Object Type Attribute Should_Be Actual Standard dummy $ 15.; input @; if _infile_ =: "==============" then do; /* go to next line*/ input; input @':' object /@':' type /@':' Attribute /@':' Should_Be /@':' Actual /@':' Standard / dummy ; output; end; else input; drop dummy; datalines; Total Exceptions Were Found Exceptions Were ignored Total Violations Were Found ============================================ Object : PLATFORM Type : SOFTWARE Attribute : LISENCE Should Be : INTACT Actual : INTACT Standard : NO =========================================== =========================================== Object : MACHINE Type : HARDWARE Attribute : CAPACITY Should Be : AMPLE Actual : UNDER Baseline : YES =========================================== ; run;
The datalines is to simulate you input file. You would not include that. Instead the INFILE would point to your file.
The length statement sets the variables as character and provides an expected length for them. If you have a better idea of the actual content for each variable you can customize the length. Note that your variable "Should be" is not a valid SAS variable name so I place and _ instead of the space. Dummy is a variable to read the following =========== divider line.
@the first input @; brings the current line of the file into a buffer to examine with the SAS special variable _infile_.
If it starts with a number of ===== characters (the =: compares the start of a string) then that is a divider line.
@AT which point we use one input; to advance to the next line that should have data. The @':' instruction on the input line says to advance the read pointer in the file to that position to start reading data. The / say "go to the next line". The / dummy says to read the following divider line.
Some caveats: If there are not exactly the same number of rows of data in the same order each time this is not going to work.
This expects two rows of ========== between the blocks of data and that the last record has a =========== following it.
If the value of any of these variables has a space in it then only the first word will be read.
Proc print would be the way to display the results if that is what you meant by print them column wise.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.