Hello!
I imported a csv file in SAS 9 and created a composite index from two variables using the following command:
proc datasets library=Work;
modify NewFile;
index create comp=(da1 da2);
run;
It was successful with a note: "Composite index comp has been defined".
But the problem is I cannot export the modified dataset with the composite index included. I have export option from file menu and also tried the following command to export:
proc export data=Work.NewFile
outfile='D:\New.csv'
dbms=csv;
run;
But all I get is the original data (csv) file which I imported without the composite index created. I am in urgent need to solve this problem quickly and thereby looking forward to any responses. If you have any suggestion in creating composite variables/index in any other methods, please provide.
Thank you.
The index is not stored in the dataset itself, so there is nothing to export.
What you need to do is to just create a composite variable, something like
comp=da1||da2
assuming DA1 and DA2 are character variables. You would need other data transformations for other data types.
Then the variable is in the file and available for export. BTW, just because you have an index does not change the order of the data in the export. To do that you need to sort the dataset.
Doc Muhlbaier
Duke
Thanks for your reply.
I tried this according to you suggestion:
proc datasets library=Work;
modify New;
comp=SELF1||SELF2;
run;
But I'm getting the following error in the log:
53 modify New;
NOTE: Enter RUN; to continue or QUIT; to end the procedure.
54 comp=SELF1||SELF2;
----
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
55 run;
My variables contain both positive and negative numericals. Is the command I've tried is correct? Can you please tell me what process SAS uses to create composite variables (I meant what calculations it does to arrive at a single value using two values).
Thank you.
I believe 'comp' is meant to be a normal SAS variable which you would create in a data step.
Data work.new;
Set have;
Length comp $ <some value>;
comp=cats(da1,da2);
Run;
...and then your process export stuff.
Thanks for the suggestion. I did it and it was successful but with typing the file name instead of 'have'. I can see from the output file that it creates composite variable by just placing the value of two variables side by side. The resulting composite variable has values very different from rest of the data. I thought composite variables are created by some mean of calculation using averages, variances, etc., and the resulting values looks alike with the rest. Also, the variances may have to be similar to the original values in each variable as very different variances result in error in structural equation modelling. I didn't find any other program but SAS to create composite variable. I'm not an expert in these issues, so any suggestions will be very much helpful.
Thank you.
Index is binded with dataset ,only contain the logic order for value of variate.
You can't export index with csv file. I do not understand what you do and what you want.
Ksharp
Thanks for viewing my problem. Using SAS, I want to create a composite variable/index from two variables both of which are interval type data (may contain positive and negative values). As I want to use this composite variable in regression, I need to save or export the created composite variable/index. This is what I couldn't do. Also, is the anyway to view the dataset in SAS which is exported?
Thank you.
Tanj,
I think that I see what is going on. "index" is a word that, in English, has multiple meanings (see http://dictionary.reference.com/browse/index for an exhaustive list).
"index", as used by SAS, is a computer science term that relates to how one orders data logically in the computer (definition 7 in reference, above)
"index", as you have just used above, is a score or algorithm. An example would be the "Dow-Jones Index" for the US Stock Market (definition 11)
In the second sense, you just use the DATA step (as Patrick described) or PROC SQL to create your score.
Doc Muhlbaier
Duke
Yes, you are right. I meant a score. But I still couldn't create the composite variable like I hoped.
Thank you.
Did you try Patrick's suggested code?
Yes I tried, but it only creates a variable by placing two values side by side.
Then you will have to explain what it is that you actually want. Some examples would be helpful.
Do you mean veiw the SAS dataset before export? There are a variety of ways depending on your installation.
If you can find the library in the SAS Explorer clicking on the icon of the desired set should open it.
Or from a SAS command line type VT libname.datasetname (VT short for Viewtable). If you want to sort or edit values in the set then add the option OPENMODE=EDIT after the VT command.
If you have the SAS AF module license FSVIEW is another tool to look at datasets.
Can you explain more what you mean by "composite" variable? Do you already have an algorithm for combining the two variables to form a new value?
Or perhaps you are looking to calculate a statistic instead of just doing a arithmetic operation?
By composite variable I meant to create a variable from two or more than two variables which will show similar trait as the component variables. This I will use in LISREL to develop SEM. The latent variables I created would be the composite variables of its indicators. I don't have an algorithm and I want to calculate of statistic as you said in the latter. Thank you.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.