BookmarkSubscribeRSS Feed
ks94
Obsidian | Level 7

Hi , 

Please i need help, I have a dataset and i want to cross-tab 8 variables . So how  SAS can use SAS to to that ? ANd if i must use contingency tables how can analyze the results ? 

thanks

7 REPLIES 7
Jagadishkatam
Amethyst | Level 16
Could you please provide sample data to help you
Thanks,
Jag
ks94
Obsidian | Level 7

hi 

I add my code to allow you to better understand my concern.

/*creer la bibliotheque*/
libname Prep "/folders/myfolders";
/*1-importer les données*/

proc import 
  datafile="/folders/myfolders/Data_projet_AFRIQUE.csv"
  out=Prep.AFRICA
  replace;
  getnames=yes;
  delimiter=';';
  guessingrows=max;
run;

/*rename the variables */

data PREP.AFRICA;
set PREP.AFRICA (rename=(case=ID_PAYS cc3=ID_PAYS_CC3 country=PAYS 
			year=ANNEE systemic_crisis=FLAG_CRISE_SYSTEMIQUE exch_usd=TAUX_CHANGE_USD 
			domestic_debt_in_default=FLAG_DETTE_INTERIEURE sovereign_external_debt_default=FLAG_DETTE_EXTERIEURE
			gdp_weighted_default=TOTAL_DETTE_PIB inflation_annual_cpi=TAUX_INFLATION
			independence=FLAG_INDEPENDANCE currency_crises=FLAG_CRISE_MONETAIRE
			inflation_crises=FLAG_CRISE_INFLATION banking_crisis=FLAG_CRISE_BANCAIRE
));

run;
/*  I change the type of some variables*/
* numeriques à caracteres*/
data prep.africa;

set prep.africa;

char_FLAG_CRISE_INFLATION = put(FLAG_CRISE_INFLATION, $15.) ;
char_FLAG_CRISE_MONETAIRE = put(FLAG_CRISE_MONETAIRE, $15.) ;
char_FLAG_CRISE_SYSTEMIQUE = put(FLAG_CRISE_SYSTEMIQUE, $15.) ;
char_FLAG_DETTE_EXTERIEURE = put(FLAG_DETTE_EXTERIEURE, $15.) ;
char_FLAG_DETTE_INTERIEURE = put(FLAG_DETTE_INTERIEURE, $15.) ;
char_FLAG_INDEPENDANCE = put(FLAG_INDEPENDANCE, $15.) ;

drop FLAG_CRISE_INFLATION;
drop FLAG_CRISE_MONETAIRE ;
drop FLAG_CRISE_SYSTEMIQUE ;
drop FLAG_DETTE_EXTERIEURE ;
drop FLAG_DETTE_INTERIEURE ;
drop FLAG_INDEPENDANCE ;


rename char_FLAG_CRISE_MONETAIRE=FLAG_CRISE_MONETAIRE ;
rename char_FLAG_CRISE_INFLATION=FLAG_CRISE_INFLATION;
rename char_FLAG_CRISE_SYSTEMIQUE=FLAG_CRISE_SYSTEMIQUE;
rename char_FLAG_DETTE_EXTERIEURE=FLAG_DETTE_EXTERIEURE;
rename char_FLAG_DETTE_INTERIEURE=FLAG_DETTE_INTERIEURE;
rename char_FLAG_INDEPENDANCE=FLAG_INDEPENDANCE;

run;

/*  caracteres à numeriques */
data prep.africa;

set prep.africa;

Num_FLAG_CRISE_BANCAIRE = input(FLAG_CRISE_BANCAIRE,best1. ) ;
Num_TAUX_CHANGE_USD = input(TAUX_CHANGE_USD,best1. ) ;

drop FLAG_CRISE_BANCAIRE;
drop TAUX_CHANGE_USD; 

rename Num_FLAG_CRISE_BANCAIRE=FLAG_CRISE_BANCAIRE;
rename Num_TAUX_CHANGE_USD=TAUX_CHANGE_USD;
run;

/*Now I want ton cross the character variable*/
/* which are 

FLAG_CRISE_MONETAIRE FLAG_CRISE_INFLATION FLAG_INDEPENDANCE
FLAG_DETTE_EXTERIEURE FLAG_DETTE_INTERIEURE*FLAG_CRISE_SYSTEMIQUE

*/

Thanks

ballardw
Super User

Details matter.

Do you want a bunch of tables of one variable crossed with another?

One or more variables crossed with other varibles?

What goes into the result of the cross tab? Counts, means, percentages (row percentage, column percentage, cell contribution to a table) or other statistics?

Do any of your variables have missing values? How are they to be treated in terms of the results?

 

Do you want a data set for further manipulation (unlikely but folks sometimes do) or a report for people to read?

 

Your SAS installation should have a small data set available called SASHELP.CLASS. You could use that to provide examples of what you want (there are only 19 records and 5 variables so not too big to look at).

Or provide your actual data and describe in much detail what you expect.

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.

ks94
Obsidian | Level 7

I already have my data. But I don't know enough about SAS. So transcribing my idea with sashelp is really not easy for me.

I have variables and I want to cross them to see if there is independence between the variables.

ballardw
Super User

Let's try this again, using variable names which variable gets crosstabbed with which variable? And what information is to be shown in the result of the cross tab?

 

What definition of "see if there is independence between the variables" are you using?

 

You went to a lot of effort to create character variables. There are some approaches to that "independence" question that are more amenable for numeric values, see PROC CORR.

ks94
Obsidian | Level 7
the variables that i want to gets crosstab are:
-FLAG_CRISE_MONETAIRE
- FLAG_CRISE_INFLATION
-FLAG_INDEPENDANCE
-FLAG_DETTE_EXTERIEURE
-FLAG_DETTE_INTERIEURE
-FLAG_CRISE_SYSTEMIQUE

ks94
Obsidian | Level 7

I have a dataset and I want to know if there is some dependency between the variables.

 

Which method SAS offer me to do that ?

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1530 views
  • 0 likes
  • 3 in conversation