10-09-2022
ShagilImam
Obsidian | Level 7
Member since
08-28-2016
- 13 Posts
- 3 Likes Given
- 1 Solutions
- 6 Likes Received
-
Latest posts by ShagilImam
Subject Views Posted 4766 10-31-2017 05:18 AM 6979 09-13-2017 02:06 AM 6998 09-12-2017 09:51 AM 7007 09-12-2017 08:18 AM 992 03-09-2017 05:40 AM 7316 01-22-2017 10:11 AM 7317 01-22-2017 10:09 AM 7322 01-22-2017 09:20 AM 7323 01-22-2017 09:14 AM 3659 01-22-2017 08:38 AM -
Activity Feed for ShagilImam
- Liked Maxims of Maximally Efficient SAS Programmers for Kurt_Bremser. 10-31-2017 06:14 AM
- Posted %SYSFUNC(SUBSTR(&VAR1,1,5)) vs %SUBSTR(&VAR1,1,5) on SAS Programming. 10-31-2017 05:18 AM
- Liked Re: Exporting a Dataset on Z/OS (Without using PROC EXPORT) for earlex. 09-14-2017 02:20 AM
- Got a Like for Re: Exporting a Dataset on Z/OS (Without using PROC EXPORT). 09-13-2017 02:31 PM
- Posted Re: Exporting a Dataset on Z/OS (Without using PROC EXPORT) on SAS Programming. 09-13-2017 02:06 AM
- Posted Re: Exporting a Dataset on Z/OS (Without using PROC EXPORT) on SAS Programming. 09-12-2017 09:51 AM
- Got a Like for Exporting a Dataset on Z/OS (Without using PROC EXPORT). 09-12-2017 08:59 AM
- Got a Like for Re: Exporting a Dataset on Z/OS (Without using PROC EXPORT). 09-12-2017 08:55 AM
- Posted Re: Exporting a Dataset on Z/OS (Without using PROC EXPORT) on SAS Programming. 09-12-2017 08:18 AM
- Posted Data Step View independent of Libref on SAS Programming. 03-09-2017 05:40 AM
- Liked Re: Informat for date in the form MM.YYYY for ChrisNZ. 01-23-2017 02:20 AM
- Got a Like for Exporting a Dataset on Z/OS (Without using PROC EXPORT). 01-22-2017 09:13 PM
- Got a Like for Re: Exporting a Dataset on Z/OS (Without using PROC EXPORT). 01-22-2017 12:10 PM
- Posted Re: Exporting a Dataset on Z/OS (Without using PROC EXPORT) on SAS Programming. 01-22-2017 10:11 AM
- Posted Re: Exporting a Dataset on Z/OS (Without using PROC EXPORT) on SAS Programming. 01-22-2017 10:09 AM
- Posted Re: Exporting a Dataset on Z/OS (Without using PROC EXPORT) on SAS Programming. 01-22-2017 09:20 AM
- Posted Re: Exporting a Dataset on Z/OS (Without using PROC EXPORT) on SAS Programming. 01-22-2017 09:14 AM
- Posted Re: Informat for date in the form MM.YYYY on SAS Programming. 01-22-2017 08:38 AM
- Got a Like for Exporting a Dataset on Z/OS (Without using PROC EXPORT). 01-22-2017 06:39 AM
- Posted Informat for date in the form MM.YYYY on SAS Programming. 01-22-2017 06:02 AM
-
Posts I Liked
Subject Likes Author Latest Post 101 1 2 -
My Liked Posts
Subject Likes Posted 1 09-13-2017 02:06 AM 1 09-12-2017 08:18 AM 1 01-22-2017 10:11 AM 3 01-22-2017 02:58 AM
10-31-2017
05:18 AM
Hello All, Can you let me know the difference between when we use a Base SAS function with %SYSFUNC vs when we use a macro function directly? For instance, what is the difference between %SYSFUNC(SUBSTR(&VAR1,1,5)) and %SUBSTR(&VAR1,1,5). Both seem to produce the same result. If there is no difference, then why do we have a separate %SUBSTR especially for Macro processing? Thanks in anticipation!
... View more
09-13-2017
02:06 AM
1 Like
I have not used DS2CSV, I just use the macro that I had created (my post). You can use it if it works for you. However, from the macro call you are using, it is clear that you are not providing the correct name of the SAS dataset which you want in CSV file. I assume that 'SGSM.PXXMT07.SASTAGSU' is the Z/OS sas library. If so, SAS dataset is contained in this library. (There may be more than one SAS dataset within this library.) Now, as you have assigned a fileref 'XXMT007' to this library, you can refer to it by this fileref. You need to know the name of the dataset which you want in the CSV file, let's say it is Dataset1. Then, the macro call should look like: %DS2CSV (DATA=XXMT007.Dataset1,RUNMODE=B,CSVFREF=XXMTCSV); P.S. what i have mentioned above is only about providing correct dataset name to the macro. I can not say that the remainig parameters have been correctly set.
... View more
09-12-2017
09:51 AM
%DS2CSV (DATA=XXMT007,RUNMODE=B,CSVFREF=XXMTCSV); Here, try giving the fileref.datasetname with the parameter DATA= You have only mentioned what you think is the fileref, but, the macro is expecting name of the dataset.
... View more
09-12-2017
08:18 AM
1 Like
Hello earlex, There should be a %UNTIL after the %DO statement. %DO %UNTIL (&RC NE 0); I see, I have missed it in my post. Apologies. However, I will suggest that you use the standard DS2CSV macro.
... View more
03-09-2017
05:40 AM
I need to create a Data Step View for an existing dataset. This view should not be require that one assign the physical path of the existing dataset to a specific Libref. I need Data Step equivalent of following PROC SQL View: Libname ViewOut "<physical path of view output library>" disp=shr; PROC SQL CREATE VIEW ViewOut.DataSetName as SELECT * FROM XYZ123.DataSetName USING LIBNAME XYZ123 "<physical path of existing output dataset>" DISP=SHR WAIT=999; QUIT; In the above PROC SQL View, the physical path of the dataset is included within the view, so, if the one has access to the view, he/she does not need to know where the actual dataset is. Thanks in anticipation!
... View more
01-22-2017
10:11 AM
1 Like
Anyway, I did learn a lot while looking for a solution myself, so i guess, it was actually time usitlised 🙂
... View more
01-22-2017
10:09 AM
Thanks Cynthia. %DS2CSV is what I really needed. I wish it had appeared in my google searches; would have saved me a lot of time 🙂
... View more
01-22-2017
09:20 AM
Thanks. My main requirement was to have the content of the dataset in CSV file, along with the names of variables as header record; similar to what PROC EXPORT does. I have simply shared the solution that I came up with.
... View more
01-22-2017
09:14 AM
Thanks. I surely would love to have a GUI client for viewing the data. We do have 'Interactive SAS', but it is a bit cumbersome to use. Also, when the output dataset is in CSV format in a text file, I can attach it in my test plan document as a proof of expected output. What I shared above, simply does what PROC EXPORT does on Windows or Unix platform. But unfortunately, PROC EXPORT did not work on the environment that we use (Z/OS), and hence, I had to come up with a different solution, shared above.
... View more
01-22-2017
08:38 AM
Hi, Thanks for your reply. 'Day' does not really matter; it can be taken as 01. I just need to read a file which will have month and year for a particular event. As I mentioned, ANYDTDTE7. works fine with hyphen or slash as separators, that is, the following code gives expected output as 10.2016 data _null_; informat dte anydtdte7.; format dte mmyyp7.; input dte; put dte; datalines; 10/2016 ; run; Taking 10-2016 in place of 10/2016 also works; but unfortunately, my input will be as 10.2016, which gives a missing value as output.
... View more
01-22-2017
06:02 AM
Hi, What informat shall I use to input a date in the form MM.YYYY (period as separator). Example: March 2016 is represented as 03.2016. ANYDTDTE7. works when hyphen (-) or slash (/) are used as separators. Returns a missing value when period is used as a separtor. Thanks.
... View more
01-22-2017
05:38 AM
In SAS, Dates are stored as numeric values. Numeric values (by default) use 8 bytes in storage. The date values are not stored as is, but are converted in to a number by calculating the number of days that have passed from 1st Jan 1960, to the given date. This number is then stored in numeric form taking up 8 bytes by default. Formats simply tell SAS how a value should be displayed. You can change the format without affecting whatever value was actually stored. For example, if you changed the format to MMDDYY5., then the dates would only display MM/YY part of the date. But that would not affect the actual value stored, so, if you went back to using the format MMDDYY10., then you would see the date how it is seen now.
... View more
01-22-2017
02:58 AM
3 Likes
Hi All, I work on SAS on Z/OS platform; we use Interactive SAS for online viewing/editing of SAS datasets. However, it is still not very user friendly as we have to use keyboard commands for every little function. Many a times, we need to analyse some SAS datasets to check whether or not our programs have given the expected output. Using Interactive SAS for this purpose (epecially when there are too many variables/observations) is a bit cumbersome and inefficient. Sadly, PROC EXPORT does not work on Z/OS platform, so there is no easy way to export the file in CSV format so that we can download it to windows and then analyse using MS Excel. (It would be great if we could do this!) With this in mind, I had to come up with a solution to be able to export any SAS Dataset including variable names as header record in CSV file. Here I am sharing my solution to the problem: Problem Statement PUT statement can be used to write an observation to a CSV flat file, however, for the generated CSV file to be usable for analysis using MS Excel, we must also know the names of variables to which each of the values in the CSV file belong. Also, the method should work with any SAS data set simply by specifying the names of the SAS dataset. The problem statements can be written down as following points: Names of variables should appear as header in delimited format in the CSV file Observations should appear as data records in delimited format in the CSV file Names of variables should correspond to its values by position in the CSV file, that is, if variable VAR1 is at position 9 (after 8 delimiters) then all its values should also be at position 9. Solution We will tackle each of the problem statements one by one. For the sake of simplifying things for later, we will assign the dataset name to a macro variable, and also write LIBNAME statement for SAS Library and FILENAME name statement for the CSV flat file. LIBNAME Libref <SAS Library that holds datset which is to be exported> DISP=SHR; FILENAME Filref <Output flat file to which the dataset will be exported> DISP=OLD; On Z/OS platform, the above LIBNAME and FILENAME statements can be achieved using DD Statements in JCL. %Let DatasetName = <name of the dataset to be exported in the form Libref.datasetname> Names of variables should appear as header in delimited format in the CSV file. We can use the PROC CONTENTS procedure with NOPRINT option and keep only the 'Name' variable to get the list of all variable names in the dataset. Proc Contents Data=&DatasetName Out=Work.VarList (Keep=Name) Noprint; Run; The code above will create a work dataset VarList with only one variable - 'Name'. This variable will give the list of all variables in the dataset given by &DatasetName. However, as we need to write the names of variables as first record in the CSV file, hence, we will need the names of variables as an observation in a dataset. PROC TRANSPOSE can be used to achieve this requirement. Proc Transpose Data= Work.VarList Out=Work.DatasetVars (Drop= _NAME_ _LABEL_); Var_ALL_; Run; The code above will create a dataset Work.DatasetVars which will have a single observation which has the names of all variables in the dataset given by &DatasetName. Next step is to write the observation in Work.DatasetVars as the first record in the CSV file. In general, PUT statement is used to write a record to a flat file. Syntax followed is: PUT Variable1 Variable2 ....VariableN; If we want to write values of all variables to the flat file, then we can use PUT (_ALL_)(+0); Code will be as follows: Data _NULL_; File CSVFILE DELIMITER=';' DSD DROPOVER; Set Work.DatasetVars; Put (_ALL_)(+0); Run; Explanation: (_ALL_) is a variable list that specifies all variables that are currently defined in the current DATA step. (_ALL_) expects to be followed by a delimiter. (+0) signifies that no delimiter should be added by the PUT statement. There is only one observation in the dataset Work.DatasetVars and it is the names of all variables in different columns. Thus the names of variables will be written to the output flat file in a semicolon delimited format. Observations should appear as data records Similar to the above step Put (_ALL_)(+0) can be used to write the observations to the output file in semicolon delimited format, however, an important requirement is that the values of variables should appear at the same position (in terms of delimiters) as the names of their corresponding variables. Names of variables should correspond to its values by position in the CSV file We can use the RETAIN statement to sequence the variables as required. For example, if we write: RETAIN Var1; RETAIN Var2; RETAIN Var3; . . . RETAIN VarN; The above will mean that the variables Var1, Var2, Var3, ....VarN will appear in the sequence in which RETAIN statements for each of the variables appears in the data step. Therefore, in order to align the data record variables with the header record variable names, all we need to do is issue a RETAIN statement for each of the values in the variable 'Name' of dataset Work.VarList. We will need to utilize SAS macro to fetch records from the dataset Work.VarList one by one, and will need to generate a RETAIN statement for each of the variable names. This can be done as follows: %macro RetainVars; %let dsid=%sysfunc(open(Work.VarList)); %do %until (&rc ne 0); %let rc = %sysfunc(fetch(&dsid)); %if &rc ne 0 and &rc ne -1 %then %put %sysfunc(sysmsg()); %else %do; %let varname = %sysfunc(getvarc(&dsid,%sysfunc(varnum(&dsid,Name)))); RETAIN &varname; %end; %end; %mend Retainvars; Now that we have the macro to write the retain statements, we can write the data step to export the observations to the CSV file. Data _NULL_ ; File CSVFILE MOD DELIMITER=';' DROPOVER; %RetainVars; Set &DatasetName; Put (_ALL_)(+0); Run; If any explanation is required, or you have any comment, please let me know. Hope this post will be helpful to someone like me out there. P.S. - I had to refer to a lot many community posts, papers, and third party websites in order to come up with the solution. Many thanks to all those who are very kind to share their knowledge.
... View more