BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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[26] $1. ('a' ... 'z'); * All letters a thru z.
ARRAY y[26] $1. ('a' ... 'z');
ARRAY z[26] $1. ('a' ... 'z');
ARRAY id[3] $1. ('x' 'y' 'z');

id = x || y || z ;

Do i = 1 to 17576;
Output;
End;
Run;

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!!
6 REPLIES 6
deleted_user
Not applicable
I don't know why but when i posted it changed my id = statement. I currently have brackets behind each one with an i in the brackets ( )

id{i} = x{i} || y{i} || z{i} ; Message was edited by: SASuser01
Cynthia_sas
SAS Super FREQ
Hi:
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.

[pre]
data testit;
length idvar $3;
do i = 'a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z';
do j = 'a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z';
do k = 'a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z';
idvar = catt(i,j,k);
output;
end;
end;
end;
run;

ods listing;
proc print data=testit;
run;
[/pre]

cynthia
deleted_user
Not applicable
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?
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

Scott Barry
SBBWorks, Inc.
Cynthia_sas
SAS Super FREQ
Hi:
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.

cynthia

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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
  • 6 replies
  • 2329 views
  • 0 likes
  • 4 in conversation