0% found this document useful (0 votes)
117 views

Read Text: Sas My Code

The document discusses various methods for reading different types of data files into SAS including text, CSV, Excel, SPSS, and directly inputting data cards. It also summarizes techniques for data manipulation like filtering, sorting, merging, creating new variables, handling missing values, and using SAS functions for string processing, random number generation, and date formatting. Finally, it mentions programming techniques like reading multiple files into one dataset and using SAS procedures for visualizing data through scatter plots and bar graphs as well as performing a t-test.

Uploaded by

Baig Aasem Raza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views

Read Text: Sas My Code

The document discusses various methods for reading different types of data files into SAS including text, CSV, Excel, SPSS, and directly inputting data cards. It also summarizes techniques for data manipulation like filtering, sorting, merging, creating new variables, handling missing values, and using SAS functions for string processing, random number generation, and date formatting. Finally, it mentions programming techniques like reading multiple files into one dataset and using SAS procedures for visualizing data through scatter plots and bar graphs as well as performing a t-test.

Uploaded by

Baig Aasem Raza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

SAS MY CODE

data salary; Data function /Salary#name anything for data


infile '/home/u49490499/main/salary (2).txt'; Infile readfuntion/ directory
input year salary; Input vaiable name/year-salary column name
run; Run runcode
READ TEXT

Infile function
DSD=[ “m” get rid of quotation mark,2,,2= in this case (csv) ,, means missing value]
MISSOVER = scan file and show missing value
FIRSTOBS = 2[first observation is second line]

For string value column variable name should end with $ example source$
data weightgain;
infile "/home/u49490499/main/weightgain (2).csv" dsd missover firstobs=2;
input id source$ type$ weightgain;
run;
READ CSV by data
proc import out=weight datafile="/home/u49490499/main/weightgain (2).csv" dbms=csv;
run;
proc print data=weight;run;

Read CSV by proc


Proc import—procedure import
proc import out=sales Proc import=import data/out=dataname
Datafile="/home/u49490499/main/Sample-Sales-Data Datafile ‘-directory’
(3).xlsx" dbms=XLSX ; Dbms =file type eg XLSX/CSV/tsv
Replace-if use will replace current data
run;
Proc print =procedure print print data
Data = data name
proc print data=sales; run;
For sheet name ‘main’ before run;
Read EXcel Sheet=”main”;
Run;

Getnames=yes/no(default=yes)
Yes get first row column name as variable

proc import out=main Proc content= give information of data


datafile="/home/u49490499/main/p054 (2).sav" Dbms = SAV
dbms=sav;
proc content data=main;
run;

proc print data= main ;run;Proc import out=main


datafile=”directory”;
Proc content data=main;
Run;
READ SPSS
data salary(keep=salary rename=salary=mainsalary); Keep—keep variable
infile '/home/u49490499/main/salary (2).txt'; Proc print data=dataname(firstobs=start obs=end)
input year salary;
run;

Date and read directly DATA filter;


Data birthday; set dataname;
Input name$ birth date11.; if var<value;
Cards; run;
Aasem 24 Apr !995
Kulsum 27 may 2011
Zeeshan 11 Sep 1997;
SAS MY CODE
Run;
Proc print data=birthday ;
Format columnname date9.
;
Run;
Createnew variable /column
Data dataname;
Infile filepath;
Input var1 var2;
Newvariablename=Calculation(eg ROUND(var1*var2);
RUN;
Data sales;
input Name$ Sales_1-Sales_4;
total=Sales_1+Sales_2+Sales_3+Sales_4;
fired='';
If name='Greg' AND Total=>52 THEN
Do;
fired='N';
end;
Cards;
Greg 10 2 40 0
john 15 5 10 100
lisa 50 10 15 50
Mark 20 2 5 20
run;
Proc sql; Proc print data=dataname(where=(SALES>050));
Select total from table RUN;
Where sales>2000;

PROC SORT DATA=DATANAME OUT=NEW; Data name;


BY COLUMN/VARIABLE; Merge df1 df2;
RUN; By column;
Run;

Data name;
Set df1 df2(rename=(names=columnname));
Run;

SAS functions
Rand ====Generate random numbers

Data …;
CALL Streaminit(12345);
Do i=1 to n;
Newvar = rand(“Normal”)
OUTPUT ;
End;
Run;

Length(doesnot count blank) Lengthn(same as first but if “ ” this counts 0) Lengthc(count blanks)=Specify
length of data in variable

TRIM ========= Get rid of trailing blanks


Newvar = trim(firstname)||’,’||(lastname);
SAS MY CODE

Compress ===========remove characters and all blanks


Data name ;
Input phone$1-15;
Phonen= compress(phone);
Phonec=compress(variablename,’(-)’,’s’);
Run;
INPUT and PUT ========conv char to numerical and viceversa
Input
Var = input(var,comma9.);
Var = put(var,8.);
CATX ========remove blanks and join /merge
Data new;
Separator = “,”;
First = ‘aasem ‘;
Last= ‘ baig’;
Result = catx(separator,first,last);
Drop separator;
Run;
SCAN-----SCAN(USED ALONG WITH CATX)variable
Data new;
Separator = “,”;
First = ‘aasem ‘;
Last= ‘ baig’;
Result = catx(separator,first,last);
Scann = scan(result,1);===give first name from result merge by catx with delimiter “,”
Drop separator;
Run;

COALESce====give unavailable variable

Numavailable = coalesce(var1,var2);
Run;
Show available
Function end with n like lengthn ===n for numerical
If end with c like lenghc====c for character

Verify =====check value present


Data name1 name2;
Input id$ stage :$5 ;
If verify(stage,’value’) then output name1;
Else output name2;
Cards/datalines;
001 value
002 othervalue
Run;
SUBSTR=====give substr in variable
Var = substr(source,postion,N);
SAS MY CODE

FLEXIBLE PROGRAMMING

Filename sales “directory/mon*.txt”; ===== read every file with mon name in it and save in sales variable to use

Data rollingquarater;
Infile sales dlm=’,’;
Input cutomer_id$ order_id order_type order_date : date9. Delivery_date : date9.;
Run;
SAS MY CODE

VISUAL Representation

Scatter plot

Proc gplot data=name;


Symbol1 value=dot cv=blue; ================ cv=color
Symbol2 value=square cv=red;
Plot var1*var2=type;
run;

BAR GRAPH
Proc gchart data=name;
Title “ naMMMMMAEAE”;
Format price dollar9;
Vbar price tax/ group =type;
Pattern color =yellow;
Run;

Statistical Analysis

T-test Independent Sample


SAS MY CODE

You might also like