I don't know if I am posting this in the right spot or not but I need some help. I am trying to make 17576 id variables ranging from aaa to zzz, that goes aab aac...aba abb ... zaa... zzz. I am trying to use array statements and do loops to do this but im not sure how to get it to work right. What I have right now is:
ARRAY x $1. ('a' ... 'z'); * All letters a thru z.
ARRAY y $1. ('a' ... 'z');
ARRAY z $1. ('a' ... 'z');
ARRAY id $1. ('x' 'y' 'z');
id = x || y || z ;
Do i = 1 to 17576;
I get an error of array subscript out of range. I think this is when i hits 27 it runs out of letters and doesn't know what to do. I am not sure where to go from here. Maybe three seperate do loops?? Any help would be greatly appreciated. Thanks!!
Well, when the array index got to be 27, since you declared the array to be a size of 26, there was no array member at 27, 28, 29, 30...etc, etc. Also, your OUTPUT statement needed to be inside the loop in order to output each unique IDVAR.
However, you don't really need an array to create your IDVAR. A do loop can iterate over a list of character constants. That is the method I use, frequently, to generate test data.
Thanks, that was very helpful. I do have another question now however. I am importing a csv file. I have to edit the data that I am pulling from the file but only have expierience with data files. Is there a way to convert the csv file into a sas data file that is delimited by commas?
In the future, please send a new post to the forum with each new question. For your second question, you can use PROC IMPORT to read your CSV file, if you want SAS to do the processing for you, otherwise you can use the DATA step technique, with INFILE statement having a DSD and DLM=',' keyword, followed by your own INPUT statement to read the CSV-formatted input file.
The SAS support website http://support.sas.com/ and its SEARCH facility can help identify SAS product documentation and also technical topic reference papers on the use of PROC IMPORT or reading an input CSV-formatted (delimited) file using a DATA step.
This really is a different question. However, the idea that a "sas data file is delimited by commas" is a foreign concept. SAS data files or data sets are stored in a proprietary file structure, that is basically tabular in structure. SAS data sets are composed of ROWS (or OBSERVATIONS) and COLUMNS (or VARIABLES). SAS data sets do not have delimiters. You may have a VARIABLE called FULLNAME, which contains values like these:
Public, John Q.
Phrog, Kermit T.
Phant, Elle E.
however, that would not be considered a "delimited" data file. That is a variable value of the form
LastName, First Middle
When you say you have to "edit the data" that you are pulling from the file, one possible scenario might be:
1) read the CSV file into a SAS dataset
2) Then, manipulate the data in the SAS dataset with the SAS programming language to (hypothetically):
2a) divide all annual salary values by 12 to create a monthly salary variable
2b) do some data cleansing and make sure that the states are all 2 character codes without punctuation (N.C. becomes NC; M.D. becomes MD, etc)
2c) do some other data manipulation
3) create a NEW CSV file from the now-edited SAS dataset as the final output after the data cleansing.
Reading the documentation on what a SAS data set is might help you come up with a better idea of the type of processing you want to perform and what your final output will be -- either SAS data set or an ASCII CSV file.